gpt4 book ai didi

javascript - 使用 Jquery 将鼠标悬停在元素的前 24 个子元素上

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

我想在前 24 个子元素上添加悬停,以在其他元素的 24 个单独元素上添加填充。

像这样:

$('tr td:nth-child(1)').mouseover(function(){
$('rect:nth-of-type(1)').css("fill", "black" );
});

$('tr td:nth-child(2)').mouseover(function(){
$('rect:nth-of-type(2)').css("fill", "black" );
});

$('tr td:nth-child(3)').mouseover(function(){
$('rect:nth-of-type(3)').css("fill", "black" );
});

但我不想重复自己 24 次。处理此问题的最佳方法是什么?

最佳答案

看看 lt 选择器:

$('tr td:lt(24)')

http://api.jquery.com/lt-selector/

关于javascript - 使用 Jquery 将鼠标悬停在元素的前 24 个子元素上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14573269/

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