我在提交之前使用jQuery验证来检查我的表单。在我的HTML中,我输入了类似的名称,ID。我想知道如何验证具有相似名称的输入而不逐一写出(类似jQuery选择具有相似名称的元素)?
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."
}
})