我正在使用 这个 jquery 验证插件
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
验证对此不起作用,但如果我将名称更改为 title
- 验证有效.
Validation doesn't work for this, but if I change the name to title
- validation works.
我尝试搜索,但找不到验证名称中带有 .
的字段的方法.
I tried searching, but couldn't find a means to validate fields with a .
in their name.
请帮忙
更新
脚本
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#contestform").validate({
submitHandler: function(form) {
// return false; // block the default submit action
},
rules: {
title: {
required: true
},
link: {
required: true
},
startdt: {
required: true
},
enddt: {
required: true
},
descr: {
required: true
},
},
messages: {
title: "Please enter a title",
link: "Please enter the sponser redirection link",
startdt: "Please select start date",
enddt: "Please select end date",
descr: "Please enter description"
}
});
});
</script>
表格的一部分
<form action="" enctype="multipart/form-data" method="post" id="contestform">
<s:hidden name="option" value="option"/>
<s:hidden name="contest.idcontest"/>
<div class="form-group">
<label for="title">Title</label>
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
</div>
你需要把字段名放在qoutes中.来自 插件文档
You need to put the field names in qoutes. From the plugin documentation
名称复杂的字段(括号、点)
Fields with complex names (brackets, dots)
当你有一个像 user[name] 这样的 name 属性时,确保把引号中的名称.一般准则中的更多详细信息.
When you have a name attribute like user[name], make sure to put the name in quotes. More details in the General Guidelines.
链接参考中的示例:
$("#myform").validate({
rules: {
// no quoting necessary
name: "required",
// quoting necessary!
"user[email]": "email",
// dots need quoting, too!
"user.address.street": "required"
}
});
这篇关于如何使用 jquery 验证插件验证名称中带有点的输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!