确定用户单击的列/行

use*_*239 4 jquery jquery-plugins datatables

使用JQuery,我需要知道用户是否单击了链接或第三列,并且需要在第一列中获取变量的值.我该怎么做呢?

我的HTML:

<div id="test">
<table id="tablex" cellpadding="0" cellspacing="0" border="0" class="display">
    <thead>
        <tr>
            <th>Cod</th>
            <th>Name completo</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
         <tr>
             <td>1</td>
             <td>John Foster 1</td>
             <td><img entity_id="1" class="image-selector" src='imagens/grid_cancel.png' title=''  /></td>
         </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

我的jQuery:

$("#tablex tbody").on("click", "td", function(event){
   alert($(this).text());
});
Run Code Online (Sandbox Code Playgroud)

Adr*_*iro 5

$("#tablex tbody").on("click", "td", function(event){
    alert($(this).index());
    alert($(this).siblings("td:first").text());
});
Run Code Online (Sandbox Code Playgroud)

$(this).index()将为您提供所点击列的从零开始的索引. $(this).siblings("td:first").text()将为您提供第一列中的文字.

在这里,有一个小提琴:http://jsfiddle.net/adrianonantua/EAEsG/