gpt4 book ai didi

javascript - 如何对表中突出显示的行进行分组 "unhighlight"

转载 作者:行者123 更新时间:2023-11-28 16:24:18 25 4
gpt4 key购买 nike

我有一个表,只要用户单击其中一行,它就会突出显示该行。但是,如果我突出显示了多行,我必须单击每个单独的突出显示行以消除突出显示。我想这样做,当一个人没有点击表格时,它会消除所有行上的突出显示。这是我正在使用的代码。

//this highlights the table that has been clicked on
$('.tr_highlight').live('click',(function () {
$(this).parent().toggleClass("tr_highlight_ed");
}));

当点击表格以外的任何地方时,如何让它取消突出显示(如果这是一个单词)?

最佳答案

您确实需要发布渲染标记的示例。你不想做一个toggleClass,你会做一个removeClass选择父节点...

假设以下标记...

<body>
...
<table id="myTable">...</table>
...
</body>

您可以绑定(bind)以下内容..

$('body').click(function(evt){
//evt.target is what was clicked on, which bubbles up to body
//if it's anything inside #myTable, you will get the #myTable
var el = $(evt.target).closest('#myTable');

//if you didn't get #myTable, you clicked outside the table
//remove the given class from all the tr's
if (!el.length) $('#myTable .tr_highlight_ed').removeClass('tr_highlight_ed');
});

关于javascript - 如何对表中突出显示的行进行分组 "unhighlight",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8540448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com