一个清洁的方式由多个可能的属性值来选择? [英] A cleaner way to select by multiple possible attribute values?
本文介绍了一个清洁的方式由多个可能的属性值来选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有jQuery的可能性由多个可能的属性值,而无需使用逗号分隔选择的列表中进行选择。
因此,在代替:
#list1的>选项[值=1]#list1的>选项[值=2]等
是这样的:
#list1的>选项[值=1|价值=2]等
解决方案
不,我知道的。在清洁的办法,我能想到这样做是首先选择使用的所有项目共同的元素,那么就 .find()
或<$的C $ C> .filter() OR值了。
像
的东西 $('#list1的&GT;选项[值]')
.filter('[值=1],[值=2]')
;
Is there a possibility in jQuery to select by multiple possible attribute values without having to use a comma separated list of selectors.
So in stead of:
#list1 > option[value="1"], #list1 > option[value="2"], etc
Something like:
#list1 > option[value="1"|value="2"], etc
解决方案
Not that I know of. The cleanest way I can think of doing this is to first select using the common elements across all items, then just .find()
or .filter()
the OR values out.
Something like
$('#list1 > option[value]')
.filter('[value="1"],[value="2"]')
;
这篇关于一个清洁的方式由多个可能的属性值来选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文