我正在尝试获取当前页面中的复选框总数,以及使用以下脚本检查了多少个复选框:
$(window).load(function() {
var chk_total=$('input[type='checkbox'].order_row:checked').length;
var in_total=$('input[type='checkbox'].order_row').length;
if (chk_total == in_total) {
alert("all cheked");
}
}
Html脚本:
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
但是上面的脚本对我不起作用。请告诉我为什么它不起作用?
答案 0 :(得分:0)
您的js脚本有错误,请按照以下步骤进行更新,然后重试。
var chk_total=$('input[type="checkbox"].order_row:checked').length;
var in_total=$('input[type="checkbox"].order_row').length;
if (chk_total == in_total) {
alert("all cheked");
}
或使用以下脚本:
var chk_total=$('.order_row:checked').length;
var in_total=$('.order_row').length;
if (chk_total == in_total) {
alert("all cheked");
}