Jquery 如何删除表第一行上的单击事件

Jquery 如何删除表第一行上的单击事件,jquery,html,html-table,click,Jquery,Html,Html Table,Click,我正在尝试用这个在表的每一行上设置click事件 这是一张表: <table border='1px'> <tr> <td class='td'>first row frist column</td> <td>first row second column</td> </tr> <tr> <td class='td'>

我正在尝试用这个在表的每一行上设置click事件

这是一张表:

<table border='1px'>
    <tr>
        <td class='td'>first row frist column</td>
        <td>first row second column</td>
    </tr>
    <tr>
        <td class='td'>second row frist column</td>
        <td>second row second column</td>
    </tr>
    <tr>
        <td class='td'>third row frist column</td>
        <td>third row second column</td>
    </tr>
</table>
使用此选项,我单击第一列中的任何一列,然后在其警报中,我要取消设置表的第一行列单击事件

如何执行此操作。

您可以使用
:not()
伪选择器从单击绑定中排除第一行

$('table tbody tr:not(:first) td:first-child')
这将向所有第一列(第一行中的第一列除外)附加一个单击处理程序。是上述内容的JSFIDLE。

您可以使用
:not()
伪选择器从单击绑定中排除第一行

$('table tbody tr:not(:first) td:first-child')
这将向所有第一列(第一行中的第一列除外)附加一个单击处理程序。是上述内容的JSFIDLE

不再推荐使用.live()方法,因为更高版本的jQuery提供了 没有缺点的更好的方法

最新版本的jquery不推荐使用
.live

试试这个

$('table tbody tr:not(:first)').on('click',function(){
alert($(this).text());
});

不再推荐使用.live()方法,因为更高版本的jQuery提供了 没有缺点的更好的方法

最新版本的jquery不推荐使用
.live

试试这个

$('table tbody tr:not(:first)').on('click',function(){
alert($(this).text());
});

试一试,演示

给所有列指定一个class
col+number
。然后使用

var i = 1;
$('td').each(function(){    
    $(this).addClass('col'+i);
    i = i+1;
});

$('table').find("td:not(.col4)").on('click',function(){
    alert($(this).text());
})
试试这个,演示

给所有列指定一个class
col+number
。然后使用

var i = 1;
$('td').each(function(){    
    $(this).addClass('col'+i);
    i = i+1;
});

$('table').find("td:not(.col4)").on('click',function(){
    alert($(this).text());
})
试试这个代码

    $('table tbody tr:not(:first-child)  td').click(function(){
alert($(this).text());
})

试试这段代码

    $('table tbody tr:not(:first-child)  td').click(function(){
alert($(this).text());
})

您可以立即排除选择器中的第一行,方法是指定它应仅适用于索引大于0的所有行:

$('table tbody tr:gt(0) td:nth-child(1)').live('click',function(){
    alert($(this).text());
});
但是,在较新的jQuery版本中,
.live
已被弃用,甚至在1.10中被删除,因此您应该改用
.on

$('table tbody tr:gt(0) td:nth-child(1)').on('click',function(){
    alert($(this).text());
});
最后,如果您曾经有过嵌套的表,那么选择器将返回太多的点击。改为选择直接子项:

$('table > tbody > tr:gt(0) > td:nth-child(1)').on('click',function(){
    alert($(this).text());
});

演示:

您可以立即排除选择器中的第一行,方法是指定它应仅适用于索引大于0的所有行:

$('table tbody tr:gt(0) td:nth-child(1)').live('click',function(){
    alert($(this).text());
});
但是,在较新的jQuery版本中,
.live
已被弃用,甚至在1.10中被删除,因此您应该改用
.on

$('table tbody tr:gt(0) td:nth-child(1)').on('click',function(){
    alert($(this).text());
});
最后,如果您曾经有过嵌套的表,那么选择器将返回太多的点击。改为选择直接子项:

$('table > tbody > tr:gt(0) > td:nth-child(1)').on('click',function(){
    alert($(this).text());
});

演示:

我认为您不必在第一行指定一个类,然后使用
onclick
事件

$('.td').on('click', function() { 
     //do your stuff here

});

希望它能有所帮助

我认为您不必在第一行给出一个类,然后使用
onclick
事件

$('.td').on('click', function() { 
     //do your stuff here

});

希望它有帮助

我想在那里设置第二列id。。。如何设置?我想设置第二列id。。。如何设置?我想设置第二列id。。。怎么做?不不不。。。我想设置第一行第二列id='second'类似于
第一行第一列第一列第二列
您想只在第一行禁用第二列?实际上,我每行有六列,所以我想删除第一行第五列类。很好的尝试,但我有六列,所有列都有相同的id='xyz'。。。所以它不可能设置手动id或classi想要设置第二列id。。。怎么做?不不不。。。我想设置第一行第二列id='second'类似于
第一行第一列第一列第二列
您想只在第一行禁用第二列?实际上,我每行有六列,所以我想删除第一行第五列类。很好的尝试,但我有六列,所有列都有相同的id='xyz'。。。因此,无法设置手动id或类