jQuery验证为数组输入添加规则 [英] jquery validate add rules for an array input
本文介绍了jQuery验证为数组输入添加规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将复选框值存储在数组中,但是,由于名称是selectList[]
而不是selectList
,所以我无法使用验证规则.我尝试使用id,但似乎规则仅绑定到该名称.
I would like to store the checkbox value in an array, however, i can not use the validate rules since the name is selectList[]
instead of selectList
. I tried id but it seems the rule only bind to the name.
html:
<input id='sendList' type='checkbox' name='selectList[]' value='$set[ListID]'>
js规则:
$("#selectList").validate( {
rules: {
selectList[]: {
required: true,
minlength: 1
}
}
})
});
谢谢
推荐答案
为什么不将selectList[]
括在引号内
$("#selectList").validate({
rules: {
'selectList[]': {
required: true,
minlength: 1
}
}
});
在初始化Javascript对象属性名称中,它们可以是标识符(您尝试的方式),数字或字符串.
In initializing Javascript object property names, they can be an identifier (the way you tried), a number or a string.
工作代码: http://jsfiddle.net/rMgLG/
这篇关于jQuery验证为数组输入添加规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文