简体   繁体   English

jQuery-隐藏表行复选框?

[英]jquery - Hide checkbox for table row?

在此处输入图片说明

Hello, how do I hide the checkbox for the table row that always contains the word "Fixed" as a link? 您好,如何隐藏始终包含单词“ Fixed”作为链接的表格行的复选框? Please see screenshot. 请看截图。 The ID and names are dynamic and always change. ID和名称是动态的,并且始终在更改。 I tried this but had no luck: 我尝试过,但是没有运气:

$( "tr:contains('Fixed')" ).find( ":checkbox" ).css( "display", "none" );

Something like this should work: 这样的事情应该起作用:

$('a').filter( function() {
    return ~$(this).text().toLowerCase().indexOf('fixed');
} ).closest('tr').find(':checkbox').hide();

The .toLowerCase() makes it case-insensitive, and the ~ is there because if indexOf() doesn't match the string, it returns -1 (0 means "at position 0"), so the bitwise NOT converts -1 into the falsey value of 0, and everything else into truthy values. .toLowerCase()使其不区分大小写,并且~在那里,因为如果indexOf()与字符串不匹配,则返回-1(0表示“在位置0”),因此按位NOT会将-1转换为假值为0,其他所有值都变为真值。

You can improve this by adding a selector to the front so it doesn't crawl every single <a> tag - something like $('table').find('a') or better yet the ID, or something more identifiable. 您可以通过在前面添加一个选择器来改进它,以使它不会抓取每个<a>标记-类似于$('table').find('a')或更好的ID,或者更易于识别的标记。

$( "tr a:contains('Fixed')" ).find( ":checkbox" ).css( "display", "none" );

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

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