请帮我解决这个问题。
我将获取驻留在 html 表中的选中复选框数组的索引号,但每次我提醒.each() 内的每个复选框的索引时,它都会为每个循环返回 0。
但是如果我删除表格及其所有 tr 和 td (不理会两个复选框),此代码将起作用
我的jQuery代码:
function notify() {
$("input[type = 'checkbox']:checked").each(function(){
alert($(this).index()); /*always return zero when the check[] inside a table or div */
});
}
function main() {
$("input[type = 'button']").click(notify);
}
$(document).ready(main);
我的html代码:
<table>
<tr><td>
<input type='checkbox' name='check[]' />
</td><td>
<input type='checkbox' name='check[]' />
</td> </tr>
</table>
<input type='button' name='button' value='ok'/>