Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过使用jQuery搜索子对象中的内容来隐藏父对象_Javascript_Jquery - Fatal编程技术网

Javascript 如何通过使用jQuery搜索子对象中的内容来隐藏父对象

Javascript 如何通过使用jQuery搜索子对象中的内容来隐藏父对象,javascript,jquery,Javascript,Jquery,我试图隐藏我正在使用find检查内容的内容的父对象。我可以将以下内容称为“本”吗 然后像这样使用它 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(

我试图隐藏我正在使用find检查内容的内容的父对象。我可以将以下内容称为“本”吗

然后像这样使用它

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:


如果筛选器与任何内容都不匹配,则将跳过隐藏。

否。
这不是魔术。将您需要重用的任何值放入变量中。我希望页面上只有一个输入框,否则选择器会提示您在页面上有重复的ID。@Ryan我之前考虑过这样做,但当我尝试时,我也没有任何运气:@Taplar Good point。我添加它只是为了确保它不会同时隐藏.input框的两个实例,并且应该更改第二个实例的id。我在这里更新了它:我更新了JSFIDLE,但它似乎不起作用:@user3561924该FIDLE不包括jQuery。打开控制台,查看错误。而且那个提琴有重复的“首选装运”ID。噢!jQueryInclude不起作用,因为我没有使用HTTPS,所以在我修复之后,它就像一个符咒一样工作!哦,老兄,你让自己很难受。在javascript部分,如果您单击框左上角显示javascript的部分,它将打开一个菜单,这样您就可以自动加载JSFIDLE提供的jQuery版本。
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();
}
$('.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();