简体   繁体   English

禁用第一列上的单击事件

[英]disable click event on first column

Can someone help me how to disable the click event on first column and the other columns should be clickable. 有人可以帮助我如何禁用第一列上的点击事件,其他列应该是可点击的。 I have tried several different ways like slice 我尝试了几种不同的方式,比如切片

td.slice() after tr element and also td:gt(0) tr元素之后的td.slice()以及td:gt(0)

etc and was unsuccessful. 等,并没有成功。 I had been banging my head since 2 days and I didn't find any relevant solutions out on google. 自从2天以来我一直在敲打我的头,我没有在谷歌上找到任何相关的解决方案。

$('#Table tbody tr').on("click",function(){
                    var aPos Table.fnGetPosition(this);
                    var aData = Table.fnGetData( aPos[6] );
                    //aData = $(this).parent().parent().html();
                    xyz = $(this).parent().parent().find("td").eq(1).html();                    
                    yzx= $(this).parent().parent().find("td").eq(7).html();
                    zxy= $(this).parent().parent().find("td").eq(2).html();
                    alert(aPos);

            });

Try stopPropogation on first column click DEMO 在第一列上单击DEMO尝试stopPropogation

Edit: Added demo and fixed .find('td:first') 编辑:添加了演示并修复了.find('td:first')

$('#Table tr').find('td:first').on('click', function (e) {
 e.preventDefault();
 e.stopPropagation();
});

add some kind of unique identifier on the first column and 在第一列添加某种唯一标识符

$('identifier').click(function(){
    return false;
});

I think you can also target first column with the n-th child thing but I am not sure of the exact syntax. 我想你也可以用第n个孩子的东西来定位第一列,但我不确定确切的语法。 Maybe something like 也许是这样的

$('table tr td:(nth-child(1)').on('click', function(){
    return false;
});

or something like the above, hope it helps 或者像上面这样的东西,希望它有所帮助

You need to add some kind of identifier to the columns you want to use: 您需要为要使用的列添加某种标识符:

<tr>
    <td class="dontClickMe"></td>
    <td class="clickMe"></td>
</tr>

Then it's as simple as: 然后它就像这样简单:

$('.clickMe').on('click', function() { ... });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM