【发布时间】:2015-11-27 15:32:21
【问题描述】:
我有一个 jquery 数据表。如您所见,其中一列包含复选框 here 。现在,当我单击行上的复选框时,它们可以正常工作。我的意思是它会打印出一个单选类复选框被选中或一个单选类复选框未被选中,因为我在事件处理程序中添加了这些。但是,如果我单击全选一次,我的各个复选框将不再运行(它不会打印出这些消息)。全选复选框看起来工作正常。 (选择所有单个框)。这是我的全选和单选复选框相关代码:
SelectAll 处理程序:
$('input[type="checkbox"][id="selectAll"]').click(function () {
if ($(this).prop("checked") == true) {
converter.checkAll(true);
} else if ($(this).prop("checked") == false) {
converter.checkAll(false);
}
});
checkAll 功能
Converter.prototype.checkAll = function (checktoggle) {
var data = (this.resultTable).fnGetData();
for (var i in data) {
var row = $('<div>' + data[i][3] + '</div> ');
row.children('input').attr('checked', (checktoggle) ? 'checked' : false);
row.children('input').attr('id', 'singleSelect');
console.log(row.html());
(this.resultTable).fnUpdate(row.html(), parseInt(i, 10), 3, false, false);
}
(this.resultTable).fnDraw();
}
单选处理程序
$('input[type="checkbox"][id="singleSelect"]').click(function () {
alert("asdasdasdasd");
if ($(this).prop("checked") == true) {
alert('one of the single select class checkbox is checked');
} else if ($(this).prop("checked") == false) {
alert('one of the single select class checkbox is unchecked');
}
});
【问题讨论】:
-
你能提供html或更好的小提琴
-
converter是什么? -
@guest271314 转换器在 Converter.prototype 函数之一中初始化为“this”关键字
-
@JSantosh 我的项目太大了,由几个依赖项目组成,所以我不知道如何为项目提供一个小提琴
-
@zwlayer "converter is initialized to 'this' keyword inside one of Converter.prototype function"
this在converter.checkAll(true);,var data = (this.resultTable).fnGetData();上是否相同?
标签: javascript jquery checkbox