单击除第一个td之外的一行 [英] Clicking a row except for the first td
问题描述
我正在尝试单击一个表行并执行一个操作。但是,如果他们点击第一个< td>
单元格,我不希望该单元执行该操作。
I am trying to click a table row and perform an action. However if they click the first <td>
cell I do not want that to perform the action.
是我现在的代码:
jQuery('#dyntable tbody tr').live('click', function () {
nTr = jQuery(this)[0];
openMessage(oTable, nTr);
});
除了第一个< td>
有一个复选框,所以如果他们点击该单元格,我不想调用o penMessage(oTable,nTr);
函数。
This works as intended, except the first <td>
has a check box, so if they click in that cell I do not want to call the openMessage(oTable, nTr);
function.
我还需要 nTr
to =行的内容。
I also still need nTr
to = the contents of the row.
推荐答案
使用行内的点击目标,并检查TD的索引
Use target of click within row, and check the index of TD
简化的演示: http://jsfiddle.net/WLR9E/
jQuery('#dyntable tbody tr').live('click', function (evt) {
var $cell=$(evt.target).closest('td');
if( $cell.index()>0){
openMessage(oTable, this);
}
});
live()被弃用,如果使用jQuery> = 1.7转换为on()。以下假设主表是页面上的永久资产。
live() is deprecated , if using jQuery >= 1.7 convert to on(). Following assumes main table is a permanent asset in page.
jQuery('#dyntable').on('click','tbody tr', function (evt) {
var $cell=$(evt.target).closest('td');
if( $cell.index()>0){
openMessage(oTable, this);
}
});
你的代码中的这行代码是redindant,它只是返回相同的这个
This line in your code is redindant, it simply returns the same as this
nTr = jQuery(this)[0];
这篇关于单击除第一个td之外的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!