gpt4 book ai didi

javascript - 如何通过使用 jQuery 在子项中搜索内容来隐藏父项

转载 作者:行者123 更新时间:2023-11-30 20:44:15 24 4
gpt4 key购买 nike

我试图隐藏我正在使用查找来检查其内容的东西的父级。我可以将以下内容称为“this”吗?

jQuery('.input-box').find('#preferred-shipping .ps-text').text().trim()

然后像这样使用它?

if(jQuery('.input-box').find('#preferred-shipping .ps-text').text().trim()==='You have backordered items in your cart, please choose a shipping status.') {
jQuery(this).closest('.input-box').hide();
jQuery(this).parent().hide();
}

这是我创建的用于测试它的 JS Fiddle:https://jsfiddle.net/Realto619/qrfytqu9/

最佳答案

$('.input-box').filter(function(){
return $(this).find('#preferred-shipping .ps-text').text().trim()==='You have backordered items in your cart, please choose a shipping status.';
}).hide();

如果过滤器不匹配任何东西,隐藏将被跳过。

关于javascript - 如何通过使用 jQuery 在子项中搜索内容来隐藏父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48914924/

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