4

它是一个 js 函数,当您从选择框中选择适当的值时,它会显示各种文本输入形式。

function arata_formular(formular) {
            document.getElementById("formular").style.visibility = "visible";
            if(document.getElementById("formular").style.display == "none" ) {
                document.getElementById("formular").style.display = "inline";
            }
            else {
                document.getElementById("formular").style.display = "visible";
            }
        }

但没有按预期工作。虽然它有一个论点,不管我将传递到那里(假设 arata_formular(entropy) 它仍然会寻找“公式”id而不是“熵”。我怎样才能插入“内联”?

不幸的是,我不能在这个或其他框架上使用 jquery。我必须只使用 javascript。谢谢!

4

2 回答 2

5

只是摆脱引号。

function arata_formular(formular) {
    var el = document.getElementById( formular );

    el.style.visibility = "visible";
    el.style.display = el.style.display === "none" ? "inline" : "visible";
}

或者


function arata_formular(formular) {
    document.getElementById( formular ).style = {
        visibility: "visible",
        display: el.style.display === "none" ? "inline" : "visible"
    }
}
于 2013-01-15T23:43:33.207 回答
3

formular是一个变量,但您像字符串一样使用它。此外,您应该缓存它:

function arata_formular(formular) {
        var el = document.getElementById(formular);
        el.style.visibility = "visible";
        if(el.style.display == "none" ) {
            el.style.display = "inline";
        }
        else {
            el.style.display = "visible";
        }
        return el;//in case you want to use the element
}
于 2013-01-15T23:46:48.833 回答