我想獲取一些複選框,並確保至少使用jQuery驗證檢查這些複選框中的一個。到目前爲止我還沒有運氣。我錯過了什麼?我知道我的驗證是在那裏,因爲它適用於其他領域,只是不適用於我的複選框。我把代碼放在jfiddle上,也許這會有所幫助。使用jQuery驗證驗證多個複選框
編輯:我添加了括號爲我的輸入名稱=列表參數(列表[])。同樣在我的規則中,我將列表中的名稱參數更改爲'list []'。我的舊代碼在下面。謝謝Sparky!
OLD: <input type='checkbox' name='list' id='fullProduct'></input>
FIXED: <input type='checkbox' name='list[]' id='fullProduct'></input>
這是我的代碼。
$("#tradeForm").validate({
rules: {
startDate: {
required: true,
date: true
},
endDate: {
required: true,
date: true
},
showName: {
required: true,
minlength: 5
},
location: {
required: true
},
list: {
required: true
}
},
messages: {
startDate: "*",
endDate: "*"
}
});
<table>
<tr>
<th>Name of Show</th>
<td> <input type='text' name='showName'></input></td>
</tr>
<tr>
<th>Location</th>
<td><input type='text' name='location'></input></td>
</tr>
<tr>
<th><span style='padding-right: 50px;'>Select Literature</span></th>
<td><input type='checkbox' name='list' id='fullProduct'></input><span style='font-size: 12px;'>Guide One</span></td>
<td><input type='checkbox' name='list' id='oilProduct'></input><span style='font-size: 12px;'>Guide Two</span></td>
</tr>
<tr>
<td></td>
<td><input type='checkbox' name='list' id='diamondProduct'></input><span style='font-size: 12px;'>Guide Three</span></td>
<td><input type='checkbox' name='list' id='motorProduct'></input><span style='font-size: 12px;'>Guide Four</span></td>
</tr>
</table>
在OP的HTML代碼是不一樣在你的jsfiddle,這也是你的問題的原因的代碼。 'name =「list []」'與'name =「list」'不一樣「。 – Sparky 2013-02-19 20:45:10