Jquery 如何使用多个is()选择器?

Jquery 如何使用多个is()选择器?,jquery,jquery-selectors,Jquery,Jquery Selectors,我试图编写一个if语句,通过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,

我试图编写一个
if
语句,通过
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')

请查看以下列表中的示例:

可以指定逗号分隔的列表:

if ($(this).parent().is('.first,.second,.third')) {
    //do this thing
} else {
    //do this other thing
}

虽然您的示例是正确的,但我认为API文档中没有明确解释或举例说明。@nipponese确实如此。在else-if子句
$(this).is(“.blue,.red”)