[英]How to find select elements in a div with id hook, the selected elements must not have parent with class .select-box?
如何在带有 id 钩子的 div 中查找选择元素,所选元素不得具有类 .select-box 的父级
HTML代码
<div id="hook">
.
.
some elements here
.
.
<select class="a">
<option>Full-time</option>
</select>
<div id="select-box">
<select class="a"> <!-- DO NOT SELECT THIS -->
<option>Full-time</option>
</select>
</div>
<select class="a">
<option>Full-time</option>
</select>
<select class="a">
<option>Full-time</option>
</select>
</div>
jQuery 代码
$('#hook').find('select').each(function(e) {
fun($(this));
});
编辑
select 元素嵌套在更多元素中。
$('#hook > select')
>
表示只选择它之前选择的内容的直接后代。 因此,只会选择作为选择元素的#hook
直接子元素。
$('#hook :not(.select-box) select').each((i, e) =>
fun($(e))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.