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