0
我有以下複選框列表,它是從服務器以HTML格式生成的。我也有一個像下面這樣的Javascript數組。 我想遍歷數組並檢查每個複選框的每個值。如果有匹配,請選中該複選框。通過比較值檢查複選框
我正在使用jQuery 1.4。
<script>
//this array is a result of an Ajax call
var arrMonth = [ "November", "October", "December"];
//Loop through the array and check each element against the check box list
//if found, make the checkbox checked
jQuery.each(arrMonth, function(intIndex, objValue) {
// script to check against the each checbox in the table ctl00_ContentPlaceHolder1_cbStudentTypeEdit
});
</script>
生成複選框列表:
<table cellspacing="10" cellpadding="20" border="0" id=
"ctl00_ContentPlaceHolder1_cbStudentTypeEdit">
<tbody>
<tr>
<td><span idkey="1"><input type="checkbox" tabindex="3" name=
"ctl00$ContentPlaceHolder1$cbStudentTypeEdit$0" id=
"ctl00_ContentPlaceHolder1_cbStudentTypeEdit_0" />
<label for="ctl00_ContentPlaceHolder1_cbStudentTypeEdit_0">October</label></span></td>
<td><span idkey="3"><input type="checkbox" tabindex="3" name=
"ctl00$ContentPlaceHolder1$cbStudentTypeEdit$2" id=
"ctl00_ContentPlaceHolder1_cbStudentTypeEdit_2" />
<label for="ctl00_ContentPlaceHolder1_cbStudentTypeEdit_2">November</label></span></td>
</tr>
<tr>
<td><span idkey="2"><input type="checkbox" tabindex="3" name=
"ctl00$ContentPlaceHolder1$cbStudentTypeEdit$1" id=
"ctl00_ContentPlaceHolder1_cbStudentTypeEdit_1" />
<label for="ctl00_ContentPlaceHolder1_cbStudentTypeEdit_1">December</label></span></td>
<td><span idkey="4"><input type="checkbox" tabindex="3" name=
"ctl00$ContentPlaceHolder1$cbStudentTypeEdit$3" id=
"ctl00_ContentPlaceHolder1_cbStudentTypeEdit_3" />
<label for="ctl00_ContentPlaceHolder1_cbStudentTypeEdit_3">January</label></span></td>
</tr>
</tbody>
</table>
謝謝。
當在頁面週期你希望這種事情發生?在document.ready上? – 2011-05-31 11:06:45