1
我正在尝试编写if
语句,该语句通过is()
检查节点的父节点是否是三个选择器之一,但is()
不支持多个选择器作为参数。我怎样才能做到与此类似?:如何使用多个is()选择器?
if ($(this).parent().is('.first','.second','.third')) {
//do this thing
} else {
//do this other thing
}
我正在尝试编写if
语句,该语句通过is()
检查节点的父节点是否是三个选择器之一,但is()
不支持多个选择器作为参数。我怎样才能做到与此类似?:如何使用多个is()选择器?
if ($(this).parent().is('.first','.second','.third')) {
//do this thing
} else {
//do this other thing
}
.first, .second, .third
是一个有效的选择:
$(this).parent().is('.first, .second, .third')
退房在API documentation of is()
的例子:
你可以指定一个逗号分隔的列表:
if ($(this).parent().is('.first,.second,.third')) {
//do this thing
} else {
//do this other thing
}
虽然你的例子是正确的,但我不认为它是明确的探究在API文档中进行了修改或举例说明。 – nipponese
@nipponese它是。在else if子句中,$(this).is(“。blue,.red”)' – djf
我纠正了。 – nipponese