javascript:在if';他的条件不符合

javascript:在if';他的条件不符合,javascript,jquery,if-statement,Javascript,Jquery,If Statement,我有以下的if测试 $("div#groupA > ul").each(function(){ if (!($("div#groupA > ul").css("display")==="none")) { $('div#groupA > ul > input[value="9999"]').remove(); } }); $("div#groupA").fadeIn(); 或 但两者都在删除之外的其他div中的 如何使其仅删除中的 谢谢

我有以下的if测试

$("div#groupA > ul").each(function(){
    if (!($("div#groupA > ul").css("display")==="none")) {
        $('div#groupA > ul > input[value="9999"]').remove();
    }
});
$("div#groupA").fadeIn();

但两者都在删除
之外的其他div中的

如何使其仅删除
中的

谢谢

试试这个:

$('#groupA').find('ul').each(function(){
    if ($(this).is(':visible')) {
        $(this).find('input[value="9999"]').remove();
    }
});
放松超特定选择器。它们对于CSS来说是有意义的,但是它们过度使用了sizzle,并且不如使用JQuery的原生遍历函数那样优化


div#groupA>ul>input[value=“9999”]
毫无意义。
符号表示以下内容是父项的直接子项。很可能你的
输入
在其他东西里面,比如
li

我用switch语句做了一些不同寻常的事情,它包含了这一点

switch(true){
    case (q1===0):
        // do some stuff
        // purposefully no break
    case (this.value==="bar"):
        $("div#groupA > ul").each(function(){
            if ( $("div#groupA > ul").css("display")!=="none" ) {
            $('div#groupA > ul > input[value="9999"]').remove();
            }
        });
        $("div#groupA").fadeIn();
        break;
    case (this.value==="foobar"):
        // do some other stuff
        break;
    default:
        // do some more other stuff
        break;
}
swtich(正确)运行良好,但我在一个案例中进行评估时除外。然后它把自己搞砸了(只做了if语句的一点点)

我最后做的是:

if(q1===0){
    // do some stuff
}
switch(this.value){
    case ("bar"):
        $("div#groupA > ul").each(function(){
            if ( $("div#groupA > ul").css("display")!=="none" ) {
            $('div#groupA > ul > input[value="9999"]').remove();
            }
        });
        $("div#groupA").fadeIn();
        break;
    case ("foobar"):
        // do some other stuff
        break;
    default:
        // do some more other stuff
        break;
}

顺便说一句,很抱歉没有立即发回邮件:当有新的回复时,它从未给我发过电子邮件。

发布你的HTML人。如果这段代码不起作用,那么问题就出在您的DOM上。我在各个方面都尝试了.is(“:visible”),但它就是不起作用,所以我必须坚持使用.css(“display”)==“无”)
if(q1===0){
    // do some stuff
}
switch(this.value){
    case ("bar"):
        $("div#groupA > ul").each(function(){
            if ( $("div#groupA > ul").css("display")!=="none" ) {
            $('div#groupA > ul > input[value="9999"]').remove();
            }
        });
        $("div#groupA").fadeIn();
        break;
    case ("foobar"):
        // do some other stuff
        break;
    default:
        // do some more other stuff
        break;
}