2

例如,我从第二页选择(选中)2行,而不是转到第一页并选择3行。当我停留在第一页时,我想从5 个选定的行中获取信息。

$('tr.row_selected') - 不工作

谢谢。

更新。

我创建了这样的处理程序:

$('#example').find('tr td.sel-checkbox').live("click", function () { /*code here*/ });

但是现在当点击事件发生时,表格中的行被隐藏了。我认为它可能是DataTables的排序或分组操作。知道我必须做什么吗?

4

2 回答 2

3

选中复选框时,将所需的行信息作为键值对存储在全局对象中

我不记得具体我以前是怎么做的,但语法类似于

$('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 了,所以按原样编写代码可能行不通,但你明白了。

于 2013-01-14T16:43:05.483 回答
3
$('#example').find('tr td.sel-checkbox').live("click", function () {
            var data = oTable.fnGetData(this);
            // get key and data value from data object
            var isSelected = $(this).hasClass('row_selected');
            if(isSelected) {
                myCheckValues[key] = value;
                checkedCount++;
            } else {
                delete myCheckValues[key];
                checkedCount--;
            }
        });

.....提交时

if(checkedCount > 0) {
            for(var ArrVal in myCheckValues) {
                var values = myCheckValues[ArrVal];   // manipulate with checked rows values data        
            }
        }
于 2013-01-16T17:45:24.797 回答