亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果跨度包含 0,則 Jquery 隱藏父標簽

如果跨度包含 0,則 Jquery 隱藏父標簽

慕虎7371278 2021-12-23 19:57:04
我有幾個標簽,如下所示:<label class="custom-control custom-checkbox mb-3">            <input type="checkbox" class="brand custom-control-input filters filter_level_100" data-filter-level="100" data-filter-type="checkbox" name="checkbox0" id="checkbox0" value="282">            <span class="custom-control-label"> BMW<span class="label label-secondary float-right brand_counts" id="brand_counts_BMW">0</span> </span> </label>現在我想隱藏標簽,如果跨度包含“0”!以下僅隱藏跨度。$(".brand_counts").filter(function(){           $(this).text().trim() === "0";        }).hide();但是如何隱藏父標簽?謝謝
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

首先,您缺少過濾器內的返回。沒有它,您將永遠找不到元素。其次,您需要將樹查找到標簽,因此您必須使用最接近的。


$(".brand_counts").filter(function() {

  return $(this).text().trim() === "0"; // you missed return here

}).closest('label').hide(); // select the grandparent with closest

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<label class="custom-control custom-checkbox mb-3">

  <input type="checkbox" class="brand custom-control-input filters filter_level_100" data-filter-level="100" data-filter-type="checkbox" name="checkbox0" id="checkbox0" value="282">

  <span class="custom-control-label"> BMW<span class="label label-secondary float-right brand_counts" id="brand_counts_BMW">0</span> </span> 

</label>


查看完整回答
反對 回復 2021-12-23
  • 1 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號