例如,我从第二页选择(选中)2 行,而不是转到第一页并选择 3 行。当我停留在第一页时,我想从选定的 5 行中获取信息。
$('tr.row_selected') - 不工作
谢谢。
更新。
我创建了这样的处理程序:
$('#example').find('tr td.sel-checkbox').live("点击", function () {
/*代码在这里*/
});
但是现在当点击事件被处理时,表中的行被隐藏了。我觉得可能是DataTables的排序或者分组操作。知道我必须用它做什么吗?
最佳答案
选中复选框后,将所需的行信息作为键值对存储在全局对象中
我不记得具体是怎么做到的,但语法是这样的
$('input[type=checkbox]').click(function()
{
var row = $(this).parent(); //this or something like it, you want the TR element, it's just a matter of how far up you need to go
var columns = row.children(); //these are the td elements
var id = columns[0].val(); //since these are TDs, you may need to go down another element to get to the actual value
if (!this.checked) //becomes checked (not sure may be the other way around, don't remember when this event will get fired)
{
var val1 = columns[1].val();
var val2 = columns[2].val();
myCheckValues[id] =[val1,val2]; //Add the data to your global object which should be declared on document ready
}
else delete myCheckValues[id];
});
提交时,从对象中获取选定的行:
for (var i = 0; i < myCheckValues.length; i++)
...
抱歉,很长时间没用过 JS,所以按原样编写代码可能行不通,但你明白了。
关于javascript - JQuery DataTables 如何在使用分页时从表中获取选定的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14321353/