[英]jQuery validate plugin validate inputs with similar names?
我正在使用jQuery validate在提交之前检查表单。 在我的HTML中,我的输入具有相似的名称,id。 我想知道如何验证具有相似名称的输入而不必一一列出(类似于具有相似名称的jQuery select元素)吗?
HTML
<form id="form1">
<table>
<tr><th>Input 1:</th><td><input type="text" name="input1" id="id_input1"/></td></tr>
<tr><th>Input 2:</th><td><input type="text" name="input2" id="id_input2"/></td></tr>
<tr><th>Input 3:</th><td><input type="text" name="input3" id="id_input3"/></td></tr>
</table>
</form>
Javascript
$("#form1").validate({
submitHandler:function(form) {
SubmittingForm()
},
rules: { //I am thinking if there has similar stuffs like
//$('th[name^="input"]')
input1: "required",
input2:"required",
input3:"required",
},
messages: {
input1: "Please finish the table.",
input2: "Please finish the table.",
input3: "Please finish the table."
}
})
对于验证部分,您只能将class =“ required”添加到您的文本字段中,它将自动对其进行验证。
至于消息,你可以参考这篇文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.