匹配两个选择器的类和数据属性时,有没有办法获得true?如何使用jquery查找匹配选择器的类和数据属性
查找匹配的下拉例如:
`<select class="type-featured" data-featured="normal">`
....
`<select class="type-featured" data-featured="classical">`
....
`<select class="type-featured" data-featured="modern">`
查找选择,类等于输入功能和数据功能的值等于正常的 - 这里是代码:
$('.style-wrapper').each(function() {
var $styles = $(this);
if ($styles.parents().find('select').is('.type-featured, [data-featured=normal]')) {
// do something here
}
});
我是否选择了TRUE有type-featured
类或data-featured="normal", data-featured="classical", data-featured="modern"
它似乎是TRUE如果匹配任何一个选择器。
使用.is函数可以得到我想要的结果吗?可以使用匿名函数,如:
.is(function() {
//here some logic to result
});
的.hasClass( )方法将返回true,如果该类被分配给e字元素。这里是类和数据分区 –