简体   繁体   English

如何让 div 在 javascript 中显示?

[英]How do I get the divs to show in javascript?

I have this script on dynamic radio buttons... On load the divs display, great.我在动态单选按钮上有这个脚本......在加载 div 显示时,太好了。 One is automatically checked, great.一个是自动检查的,太好了。 If I click the other radio button the divs hide, great.如果我单击 div 隐藏的另一个单选按钮,那就太好了。 When I click back to the main radio button to show the divs again the divs don't reappear.当我单击返回主单选按钮以再次显示 div 时,div 不会重新出现。

How do I get the divs to reappear (show)?????如何让 div 重新出现(显示)??????

 function hide() {
        var ele = document.getElementById("hideRow");
        var coup = document.getElementById("coup");
        if ("hideRow") {
            ele.style.display = "none";
            coup.style.display = "none";
        } else {
            ele.style.display = "block";
            coup.style.display = "block";
        }
    }

Try:尝试:

function hide() {
    var ele = document.getElementById("hideRow");
    var coup = document.getElementById("coup");
    if (ele.style.display == "block") {
        ele.style.display = "none";
        coup.style.display = "none";
    } else {
        ele.style.display = "block";
        coup.style.display = "block";
    }
}

This is always true:这总是正确的:

if ("hideRow") {
    // Always executes
}

So, you only ever get to the if-block.因此,您只能进入 if 块。 You need to change the conditional on your if-statement.您需要更改 if 语句的条件。

if (ele.style.visibility == 'visible';) {
        ele.style.visibility = 'hidden';
        coup.style.visibility = 'hidden';
    } else {
        ele.style.visibility = 'visible';
        coup.style.visibility = 'visible';
    }

I may have entirely missed the mark and not understood what your trying to do, but that's the way I'd do it (I think - you may be trying to do something else).我可能完全错过了标记并且不明白你想要做什么,但这就是我这样做的方式(我认为 - 你可能正在尝试做其他事情)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM