jQuery验证带有方括号的表单名称 [英] jQuery validation of a form name with square brackets
本文介绍了jQuery验证带有方括号的表单名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为文本字段提供了以下验证代码,但是下面的字段"需要替换为动态创建的文本字段的名称.
I have the following validation code for a text field but the 'field' below needs to be replaced with the name of the text field, which is created dynamically.
我的问题是名称中有一个方括号-options[483998]
My problem is it has a square bracket in the name - options[483998]
如何将其添加到下面的代码中,显然,如果我直接用options[483998]
替换字段,则会创建无效的编码.
How would I go about adding this to the code below as obviously if I do a direct replace of field with options[483998]
it creates invalid coding.
jQuery("#product_addtocart_form").validate({
rules: {
field: {
required: true,
range: [100, 2540]
}
}
});
推荐答案
演示- http://jsfiddle.net/sY82j/
jQuery("#product_addtocart_form").validate({
rules: {
"options[483998]": {
required: true,
range: [100, 2540]
}
}
});
这篇关于jQuery验证带有方括号的表单名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文