gpt4 book ai didi

javascript - 处理 tr 的子元素不起作用

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

我刚刚又被卡住了,也许其他人可以更容易地发现问题。第一个 tr 的子项(例如表格单元格)在使用此代码悬停时不会更改背景:

$("#target tr:eq(1).find("*")").hover(function(){
$(this).css("background", "#fff");
})


<table id="target">
<tr><td\>
content
</td></tr>
<tr><td\>
content
</td></tr>
</table>

是引号吗?

最佳答案

.find()

$("#target tr:eq(1)").find("*").hover(function () {
//^^ move find outside the seletor
$(this).css("background", "#fff");
});

Demo

:eq() 索引从 0 开始,如果你想第一个跟踪我们 .eq(0)


找回旧颜色

Demo

$("#target tr:eq(1)").find("*").hover(function () {
$(this).css("background", "#fff");
},function(){
$(this).css("background", "blue"); //get old color back
});

关于javascript - 处理 tr 的子元素不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807359/

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