本文介绍了如果同时没有2个CSS类,如何隐藏div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面上大约有20个div标签,其中指示了几个类(但所有类都具有"delivery-table-item"类,这是必需的).如何隐藏同时没有2个必要类的div.我写了一个小脚本,但它一次隐藏了所有div,我在哪里出错了?

There are about 20 div tags on the page, in which several classes are indicated (but all have the class "delivery-table-item", it is required). How to hide div in which at the same time there are no 2 necessary classes. I wrote a small script, but it hides all the divs at once, where did I make a mistake?

var deliveryVal = $('#f-select-delivery').val();
var statusVal = $('#f-select-status').val();
var dti = $('.delivery-table-item');
if( dti.not('.' + deliveryVal) && dti.not('.' + statusVal) ){
  $('.delivery-table-item').hide();
}

推荐答案

您只需按照以下步骤在一行中完成

you can simply do it in one line as following

$('.delivery-table-item:not(.deliveryVal) ,.delivery-table-item:not(.statusVal)').hide();

您的解决方案是错误的,因为您选择的条件div没有deliveryVal

your solution is wrong becauseyour if condition you selectdivs dosen't have deliveryVal class

$('.delivery-table-item').not('.deliveryVal')

和div没有statusVal

$('.delivery-table-item').not('.statusVal') )

对他们什么也不做然后在if主体内,使用以下语句隐藏所有div

and do nothing with themthen inside the if body you hide all divs using following statement

   $('.delivery-table-item').hide();

所以最后您的解决方案就像检查是否有divs没有statusVal类,并且有divs没有statusVal类,然后隐藏所有divs

so at the end your solution is like check there is divs dosen't have statusVal class and there is divs dosen't have statusVal class then hide all divs

这篇关于如果同时没有2个CSS类,如何隐藏div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 22:34