gpt4 book ai didi

javascript - 在javascript上,如何在类属性上使用 sibling

转载 作者:行者123 更新时间:2023-12-02 17:54:04 24 4
gpt4 key购买 nike

我对 JS 很菜鸟。我需要使用 html 代码选择 data-parent="16"的元素:

    <div class="filter-options" id="able-filter">
<div class="Xhaut" id="Xhaut">
<a class=" active" data-dimension="region" data-filter="all" href="javascript:void(0)">All</a>
<a data-term_id="18" data-parent="17" data-filter="villebelge1" href="javascript:void(0)" class="a" data-dimension="region">villeBelge1</a>
<a data-term_id="19" data-parent="17" data-filter="villebelge2" href="javascript:void(0)" class="a" data-dimension="region">villeBelge2</a>
<a data-term_id="20" data-parent="17" data-filter="villebelge3" href="javascript:void(0)" class="b" data-dimension="region">villeBelge3</a>
<a data-term_id="21" data-parent="16" data-filter="villenord1" href="javascript:void(0)" class="b" data-dimension="region">villenord1</a>
<a data-term_id="22" data-parent="16" data-filter="villenord2" href="javascript:void(0)" class="c" data-dimension="region">villenord2</a>
<a data-term_id="23" data-parent="15" data-filter="villesud1" href="javascript:void(0)" class="c" data-dimension="region">villeSud1</a>
<a data-term_id="24" data-parent="15" data-filter="villesud2" href="javascript:void(0)" class="d" data-dimension="region">villeSud2</a>
<a data-term_id="25" data-parent="15" data-filter="villesud3" href="javascript:void(0)" class="d" data-dimension="region">villeSud3</a>

</div>
</div>

我尝试过这种事情:

    var Xhaut = $('#Xhaut').find('a');
window.console && console.log(Xhaut);
window.console && console.log(Xhaut.siblings(".d")); // thi it ok I have villesud2 and villesud3, it's ok because I use a class selector

// But how can I select all element with data-parent="16" (not class="d", but data-parent="16")

我做了一个 fiddle : http://jsfiddle.net/bakalegum/2DGHD/

非常感谢。

编辑:感谢您的回答!

最佳答案

你可以这样做:

var Xhaut = $('#Xhaut').find('[data-parent=16]');

http://api.jquery.com/attribute-equals-selector/

关于javascript - 在javascript上,如何在类属性上使用 sibling ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21119272/

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