jQuery可点击表格行,带有特定类名的td除外

fre*_*rks 4 jquery tablerow clickable

我有这样的桌子

<tbody>
   <tr class="row-links" data-link="http://mylink.com">
     <td>some cell</td>
     <td>some cell</td>
     <td>some cell</td>
     <td class="special-td"><a href="http://followthis.com">special cell</a></td>
     <td>some cell</td>
     <td class="special-td">special cell</td>
     <td>some cell</td>
   </tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)

我想使整行都可单击,希望有一些“特殊单元格”,我已经给它们指定了一个识别类名“ specal-td”

通常,整行的链接存储在“数据链接”属性中

到目前为止,我想出的代码不起作用如下:

$('.row-links td:not(.special-td)').on('click', function(e){


    //get the link from data attribute
    var the_link = $(this).attr("data-link");

    //do we have a valid link      
    if (the_link == '' || typeof the_link === 'undefined') {
        //do nothing for now
    }
    else {
        //open the page
        window.location = the_link;
    }
});
Run Code Online (Sandbox Code Playgroud)

任何帮助都是最欢迎的

更新:

多亏了(PhoenixWing156&MDJ)的支持,工作代码现在看起来像这样

$('.row-links').on('click', 'td:not(.special-td)', function(){


    //get the link from data attribute
    var the_link = $(this).parent().attr("data-link");

    //do we have a valid link      
    if (the_link == '' || typeof the_link === 'undefined') {
        //do nothing for now
    }
    else {
        //open the page
        window.location = the_link;
    }
});
Run Code Online (Sandbox Code Playgroud)

MDJ*_*MDJ 5

$('.row-links').on('click', 'td:not(.special-td)', function(){
   //Do something
});
Run Code Online (Sandbox Code Playgroud)