我有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
对不起,我会编辑帖子(除了真码以外,很快) –