JQuery在Div中按ID隐藏标签

pcww981p  于 2023-06-22  发布在  jQuery
关注(0)|答案(2)|浏览(121)

我有一些div在创建时动态添加“fund-id”属性,因为我的页面上可能有大约50个div。我试图动态地隐藏和显示元素的基础上的基金id和标签id的div的HTML将;

<div class="qtyDD" id="divqtyDD" style="display: none;" fund-id="1">
    <a href="#" onclick="javascript:changeQtyType('D');"><label id="qtyTypeD" class="lblqtyDD" value="D">Dollars</label></a>
    <a href="#" onclick="javascript:changeQtyType('Shrs');"><label id="qtyTypeShrs" class="lblqtyDD" value="Shrs">Shares</label></a>
    <a href="#" onclick="javascript:changeQtyType('Full');"><label id="qtyTypeFull" class="lblqtyDD" value="Full">Full</label></a>
    <a href="#" onclick="javascript:changeQtyType('Net');"><label id="qtyTypeNet" class="lblqtyDD" value="Net">Net Redemptions</label></a>
</div>

根据复选框的选择,我想要隐藏();最后3个元素或全部显示。类似的东西;

var fundID = fundID (taken from the function call, this is working fine)
if(this.checked){
   $('#divqtyDD[fund-id="' + fundID + '"]').next('#qtyTypeShrs').hide();
}else{
   $('#divqtyDD[fund-id="' + fundID + '"]').next('#qtyTypeShrs').show();
}

标签在被下一个功能引用时不会隐藏。任何帮助都是感激的。

jfgube3f

jfgube3f1#

尝试

$("#divqtyDD").children("#qtyTypeD").hide();

或者你可以直接使用

$("#qtyTypeD").hide();

因为ID是唯一的。

fhity93d

fhity93d2#

$("#divqtyDD").children().slice(1)[this.checked ? 'hide' : 'show']();

相关问题