使用 jquery 进行动态文本框验证
我的表单中有动态文本框。我喜欢使用 bassistance jquery 插件进行验证。
http://bassistance.de/jquery-plugins/jquery-plugin-validation /
我的文本框名称位于数组格式设置[]中,如何表示规则和消息
<input type="text" name="setting[]">
我的验证脚本是
<script type="text/javascript">
$("#freebidz_frm").validate({
rules: {
setting:{
required: true
}
},
messages: {
setting: '<br>'+"Please enter Default Font Style"+''
}});
</script>
但它不起作用......有人帮助我!提前致谢
I am having dynamic text box in my form . I like to validate using bassistance jquery plugin.
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
My textbox name is in array formate setting[], how to represent rules and messages
<input type="text" name="setting[]">
my validation script is
<script type="text/javascript">
$("#freebidz_frm").validate({
rules: {
setting:{
required: true
}
},
messages: {
setting: '<br>'+"Please enter Default Font Style"+''
}});
</script>
But it's not working ... somebody help me ! Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不管其他人怎么说,在输入名称中包含方括号是有效的(而且有用)(但是对于 ID 无效)。大多数服务器端语言会将它们作为数组进行处理,这可以在编写处理时节省大量时间。
至于你的脚本,有两点可能会出错:
我已将您的代码复制到新的 HTML 页面中,并且当我进行这两项调整时,验证脚本可以正常工作。请确保在脚本的“规则”和“消息”部分中将“设置[]”括在引号中。
由于您是根据输入创建数组,因此我假设这不是表单中唯一的“setting[]”。如果是这种情况,您将不得不变得更花哨 - 创建类规则可以帮助您验证基于公共类的一组输入(http://docs.jquery.com/Plugins/Validation/Validator/addClassRules) 。
Despite what others are saying, it's valid (and useful) to include square brackets in your input names (invalid for IDs, however). Most server-side languages will process these as an array, which can save you a lot of time when writing the processing.
As for your script, there are two points where it may be going wrong:
I've copied your code into a new HTML page and the validation script worked properly when I made these two adjustments. Just be sure to wrap 'setting[]' in quotes in both the 'rules' and 'messages' parts of the script.
Since you're creating arrays from your inputs, I'm assuming this isn't the only 'setting[]' in the form. If that's the case, you'll have to get a little fancier - creating class rules can help you validate a set of inputs based on a common class (http://docs.jquery.com/Plugins/Validation/Validator/addClassRules).