javascript根据计算值显示div元素

时间:2018-04-19 15:18:13

标签: javascript html

我试图根据计算值显示不同的div元素,基本上是

if(x <= total){display y <div>} else {display z <div>}

我无法弄清楚我需要捕获div的哪一部分来显示div,现在我的条件语句不起作用,它只显示按下按钮后的div。 var surlyValue正在正确设置。这是按钮的HTML

<button type="button" onclick="show('fixingSteps');">What Do I Need To Do?</button> 

这是2个选项的HTML

<div class="side-by-side" id="fixingSteps" name="fixingSteps" style="background: aquamarine; display: none">
            <h1>Recommended Mitigations</h1>
            <div> Smile, Everyone Should Be Happy, No Mitigations are Neccessary!!!!</div>
        </div>

        <div class="side-by-side" id="fixingSteps" name="fixingSteps1" style="background: aquamarine; display: none">
            <h1>Recommended Mitigations</h1>
            <div>
                <select id="mitS" name='mitS' onchange="calculateTotalWithMitigation()">
                    <option value="none">Select Input</option>
                    <option value="mit1">Mitigation 1</option>
                    <option value="mit2">Mitigation 2</option>
                    <option value="mit3">Mitigation 3</option>
                    <option value="mit4">Mitigation 4</option>
                    <option value="mit5">Mitigation 5</option>
                </select>
            </div>

这就是我试图使用的JS函数

function show(elementId) {

var surlyValue = getValue();

if (surlyValue < 10) {
    document.getElementById("fixingSteps").style.display = "none";
    document.getElementById(elementId).style.display = "block";
} else {
    document.getElementsByName("fixingSteps1").style.display = "block";
}
}

感谢您帮助我学习如何在此示例中使用JS

0 个答案:

没有答案