gpt4 book ai didi

javascript - 检查数据属性和应用逻辑失败

转载 作者:行者123 更新时间:2023-11-28 00:39:56 26 4
gpt4 key购买 nike

在每个 div - smallCatalogBlock 中,我有一个名为 data-availability 的数据属性,带有"is"或“否”。我正在尝试检查数据属性的值。如果不是,我想要 catalogSmallCircle,专门用于隐藏该 div。

到目前为止,什么都没有发生。

有没有人看到我做错了什么?根据我的尝试,“紧固技术”按钮应该被隐藏。

var availability = $('.smallCatalogBlock').data('availability');
$('.smallCatalogBlock').each(function(index, catalogBlock){
catalogName = $(catalogBlock).data('fill-specs');
console.log('catalog name ' + catalogName);
if (availability == 'No') {
console.log(availability);
$('.catalogSmallCircle').hide();
}
//Filling Circle
$('.catalogSmallCircle', catalogBlock).html(
'<div class="catalogSmallCircleIn" data-catalog-name='+ catalogName +'><div class="total-center"><div class="circlePlus"></div></div></div><div class="catalogCircleExpand"><div class="catalogExpandClose"></div><div class="total-center expandText"><span class="catalogName pdfSubHeader"></span><p class="dGw circleExpandText"></p><button class="catalogDownload downloadButton" name="Profile_Catalog" data-catalog-now="Profile Small Catalog Button" data-catalog-view-name="Profile Catalog">View</button><button class="catalogDownload requestButton" data-catalog-name="'+ catalogName +'">Request</button></div></div>'
)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="smallCatalogWrap">
<div class="smallCatalogBlock" data-fill-specs="Profile-Catalog" data-availability="Yes">
<span class="smallCatalogTitle">Profiles and Caps</span>
<div class="smallCatalogButtonWrap">
<div class="catalogSmallCircle"></div>
</div>
</div><div class="smallCatalogBlock comingSoonSmall" data-fill-specs="Fastening Technology" data-availability="No">
<span class="smallCatalogTitle">Fastening Technology</span>
<div class="smallCatalogButtonWrap">
<div class="catalogSmallCircle"></div>
</div>
</div>
</div>

最佳答案

改变

    if (availability == 'No') {
console.log(availability);
$('.catalogSmallCircle').hide();
}

if ($(this).data('availability') === 'no') {
console.log(availability);
$(this).find('.catalogSmallCircle').hide();
}

关于javascript - 检查数据属性和应用逻辑失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54080632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com