1

送信する前に、jQueryvalidateを使用してフォームを確認しています。私のHTMLには、同じような名前、IDの入力があります。1つずつ書き出さずに類似した名前の入力を検証する方法を知りたいです(類似した名前の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."  
          }
})
4

1 に答える 1

1

検証部分については、テキストフィールドに class="required" のみを追加でき、自動的に検証されます。

メッセージについては、この投稿を参照できます

于 2012-09-04T15:04:20.063 に答える