jquery - 如何删除表格第一行的点击事件

标签 jquery html html-table 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>

这是简单的 jQuery:-

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

有了这个,我点击第一列的任何一个,然后在它的警报中我想取消设置表第一行列的点击事件。

我该怎么做。

最佳答案

试试这个,DEMO http://jsfiddle.net/yeyene/CGbXP/4/

给所有列一个类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());
})

关于jquery - 如何删除表格第一行的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17875242/

相关文章:

javascript - 为什么每次点击时数组都会重新初始化?

javascript - 如何在IE中以其原始平滑度显示图像

jquery - recaptcha 在 bootstrap 3 底部页面显示空白

javascript - 是否可以使用 javascript 确定卷轴的最终位置?如果是这样,如何?

HTML 表格标题始终显示在窗口顶部

javascript - Javascript 中的 HTML 表条件格式代码未按计划工作

javascript - TinyMCE 自定义主题 - bullist numlist 链接取消链接不起作用

javascript - Telerik MVC 控件,OnDocumentReady 触发两次

html - CSS:我想在一个容器中分别定位每个 child

html - 将最小大小限制为 html 表