var container = $(".container"),
background = $(".background");
// ...
// Inside an each() method – check if is container OR background
if (this.is(container, background)) { // Not working
// do something
}
// I know I could do it like this ...
if (this.is(container) || this.is(background)) {
// do something
}
// ... but I want it shorter
甚至可以使用is()将多个选择器作为变量进行检查吗?
你可以使用这个选择器
this.is('.container, .background')
所以基本上,1)
if (this.is('.container, .background')) {
// do something
}
2)
var elements = ('.container, .background');
if (this.is(elements)) {
}
3)
if (this.is([container[0], background[0]])) {
// do something
}
4)
if (this.is(container.add(background))) {
// do something
}
5)
var temp = container.add(background);
if (this.is(temp)) {
// do something
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句