gpt4 book ai didi

jQuery 选择包含链接的元素,该链接包含数组的任何元素

转载 作者:行者123 更新时间:2023-12-01 04:30:47 25 4
gpt4 key购买 nike

我正在尝试制定一个复杂的 jQuery 选择。我有一个数组,我需要选择包含链接 a.bardiv.foo ,并且该链接的 href 包含任何字符串在数组中。

例如:

<html>
<div class=foo>
some text
<a class=bar href=example.com?q=widget&id=23456789>search</a>
</div>
</html>

和 jScript

widgets[0]='12345678';
widgets[1]='23456789';
widgets[2]='34567890';

我想突出显示此 div,因为查询字符串包含 23456789,它是 widgets[] 中的元素之一。

谢谢

最佳答案

$('div.foo > a.bar[href*=23456789');

select all a which contains '23456789' in the href attributes with the bar class which are direct descendant of all div with a class foo.

for (num in widgets)
{
$('div.foo > a.bar[href*=' + num + ']').doSomething();
}

关于jQuery 选择包含链接的元素,该链接包含数组的任何元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699072/

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