我有20個div,每一個speficif類,所以我選擇它,並檢查是否是4'特殊'的1。Javascript多個語句在一個單一的,如果不工作
的主要問題是,下面的代碼應該工作...
$('.cbp-ig-grid li, .cbp-ig-grid li a span object').on('click', function() {
/* Variables Definition */
var item = $(this).find('span').attr('class').split(' ')[1]
}
if((item != 'item1') || (item != 'item2') || (item != 'item3') || (item != 'item4')){
// Always enters here!
}else{
// Never enters here :( (I need to enter here for the 4 cases in the if statement)
}
但是當我只是一個做...它的作品!
if(item != 'item1'){
// do stuff
}else{
// do other stuff
}
我不知道我做錯了,請幫忙將是有益的
是的,它可能是,但它需要把它作爲變量ble,而不是再次選擇:/ –
除此之外,你的Javascript看起來不是有效的。找到你的物品後,丟失一個''''並且移除''''。 – NiZa
對不起,我會編輯帖子(除了真碼以外,很快) –