javascript使用类名找到第二行

时间:2015-08-21 14:14:31

标签: javascript jquery

我试图在类名中获得第二行和值 使用(javascript)

 var doneData=$('#datatable_fixed_column tr').find('.donex').eq(1).text();
    alert(doneData);

但它在这里不起作用是表格(html)的样本

<table id="datatable_fixed_column" width="100%">
    <thead>
    <tr class="codexTotal" >
    <th > 1 </th>
    <th >2</th>
    <th >3</th>
    <th >4</th>
    <th >5</th>
    <th class="donex">6</th>
    <th class="hider waitx">7</th>
    </tr>
    </thead>
    <tbody>
    <tr class="codexTotal">
    <td >data1</td>
    <td>data2</td>
    <td>data3</td>
    <td>data4</td>
    <td>data5</td>
    <td class="donex">Get this data</td>
    <td class="hider waitx">Get this data</td>
    </tr>
    </table>

1 个答案:

答案 0 :(得分:0)

我设法解决问题,使用.dataTable()。fnSettings()。aoDrawCallback.push,这将检测数据表中的变化,首先我生成id

                    { "data": "1" },
                    { "data": "2" },
                    { "data": "3" },
                    { "data": "4" },
                    { "data": "5" },

                    {
                        "className": 'hider',
                        "orderable": false,
                        "data": function (row, type, val, meta) {
                            return '<div id="donerx'+meta.row+'">'+row['getData1']+'</div>'
                        }
                    },
                    {
                        "className": 'hider',
                        "orderable": false,
                        "data": function (row, type, val, meta) {
                            return '<div id="waitrx'+meta.row+'">'+row['getData2']+'</div>'
                        }
                    }

然后我添加函数,找到我需要的东西

 $('#datatable_fixed_column').dataTable().fnSettings().aoDrawCallback.push({
                "fn": function () {

            var donerx = document.getElementById("donerx0").textContent;
                   alert(donerx);

                }
            });