2

我为datatable编写简单的contexMenu。我正在使用datatables类来创建数据列表。我想找到表格的第一个单元格右键单击每个单元格,我怎样才能找到它?

对不起我的英文 jquery:

    $("#showTopics tbody").bind("contextmenu",function(event) {
        var aata = $(this).children('tr').children('td').eq(0).text();
        alert(aata);
    return false;
});

HTML

<table id='showTopics' style='line-height:18px;'>
    <thead>
        <tr>
            <th style='width:30%;text-align:right;'>X"</th>
            <th style='width:7%;'>a</th>
            <th style='width:12%;'>b</th>
            <th style='width:11%;'>c</th>
            <th style='width:9%;'>d</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
4

2 回答 2

0

尝试这个:

$("#showTopics tr").bind("contextmenu",function(event) {
    var aata = $(this).children().siblings(':first').text();
    alert(aata);
    return false;
});
于 2013-05-16T07:57:06.483 回答
0

这对我有用。小提琴: http: //jsfiddle.net/FaRSa/ 但是在您的示例中,您只将事件放在$("#showTopics tbody"). 并且您的 HTML 仅在thead

在小提琴中,我在 tbody 中加入了另一个 tr 并且该功能运行良好。:)

于 2013-05-16T07:49:36.707 回答