我正在尝试构建一组中所有选定复选框的值的数组(我在此页面上有多个复选框组,但下面是其中之一)。
当我点击一个复选框时,我首先收到一个值为“0”的警报,然后是一个值为“1”的警报。这正如预期的那样。但是,当我选中第二个复选框时,警报不再出现。我的 Chrome 控制台中也没有看到任何错误。
为什么?
HTML
<table id="CPHCenter_cblFeatures" class="cblist textbox" style="width:100%;">
<tbody>
<tr>
<td>
<input id="CPHCenter_cblFeatures_0" type="checkbox" name="ctl00$CPHCenter$cblFeatures$0" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$0\',\'\')', 0)" value="6">
<label for="CPHCenter_cblFeatures_0">Arbor</label></td>
<td><input id="CPHCenter_cblFeatures_4" type="checkbox" name="ctl00$CPHCenter$cblFeatures$4" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$4\',\'\')', 0)" value="7"><label for="CPHCenter_cblFeatures_4">Disabled access</label></td>
</tr><tr>
<td><input id="CPHCenter_cblFeatures_1" type="checkbox" name="ctl00$CPHCenter$cblFeatures$1" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$1\',\'\')', 0)" value="3"><label for="CPHCenter_cblFeatures_1">Beach</label></td>
<td><input id="CPHCenter_cblFeatures_5" type="checkbox" name="ctl00$CPHCenter$cblFeatures$5" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$5\',\'\')', 0)" value="4"><label for="CPHCenter_cblFeatures_5">Forest</label></td>
</tr><tr>
<td><input id="CPHCenter_cblFeatures_2" type="checkbox" name="ctl00$CPHCenter$cblFeatures$2" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$2\',\'\')', 0)" value="1"><label for="CPHCenter_cblFeatures_2">Bridal suite</label></td>
<td><input id="CPHCenter_cblFeatures_6" type="checkbox" name="ctl00$CPHCenter$cblFeatures$6" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$6\',\'\')', 0)" value="2"><label for="CPHCenter_cblFeatures_6">Garden</label></td>
</tr><tr>
<td><input id="CPHCenter_cblFeatures_3" type="checkbox" name="ctl00$CPHCenter$cblFeatures$3" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$3\',\'\')', 0)" value="5"><label for="CPHCenter_cblFeatures_3">Dancing room</label></td>
<td><input id="CPHCenter_cblFeatures_7" type="checkbox" name="ctl00$CPHCenter$cblFeatures$7" onclick="javascript:setTimeout('__doPostBack(\'ctl00$CPHCenter$cblFeatures$7\',\'\')', 0)" value="8"><label for="CPHCenter_cblFeatures_7">Water</label></td>
</tr>
</tbody>
</table>
jQuery
function getresults() {
var arr = new Array();
$.each($("input[name*='cblFeatures']:checked"), function () {
arr.push($(this).val());
});
alert(arr.length);
arr = new Array();
return true;
}
$(document).ready(function () {
$("#<%=cblFeatures.ClientID%>").click(function () { getresults(); });
});