我有一个包含 16 个复选框的表单。我正在尝试跟踪选中的框的数量并在表单下方提供即时反馈,但我无法获取 numSelected 变量来更新更改。
这是我的脚本:
$(document).ready(function () {
// the jQuery.iCheck library wraps the input in a div for styling
$('input').iCheck({
checkboxClass: 'icheckbox_square-red'
});
// count the checkboxes
var cb = $(":checkbox"),
numSelected = 0,
numLeft = 2 - parseInt(numSelected, 10);
$(cb).change(function () {
//alert("a checkbox was checked!");
var $this = $(this);
var numSelected = $this(':checked').length;
$('#status-box').html("Out of "+$this.length+" images you have selected "+numSelected+" for processing, you have "+numLeft+" remaining");
});
});
这是我放在一起的jsfiddle ,感谢您的帮助!