【发布时间】:2017-01-24 13:01:11
【问题描述】:
有没有办法同时匹配选择器类和数据属性?
查找匹配的下拉菜单,例如:
`<select class="type-featured" data-featured="normal">`
....
`<select class="type-featured" data-featured="classical">`
....
`<select class="type-featured" data-featured="modern">`
找到select,class等于type-featured AND data-featured value等于normal - 这里是代码:
$('.style-wrapper').each( function() {
var $styles = $(this);
if ( $styles.parents().find('select').is('.type-featured, [data-featured=normal]') ) {
// do something here
}
});
无论选择有type-featured 类还是data-featured="normal", data-featured="classical", data-featured="modern",我都得到了TRUE
如果匹配任何一个选择器,它似乎是 TRUE。
是否可以使用 .is 函数获得我想要的结果?可能正在使用匿名函数,例如:
.is( function() {
//here some logic to result
});
【问题讨论】:
标签: javascript jquery jquery-selectors