javascript - 提交时显示 div

标签 javascript html css

我想显示一个 div(取决于输入的值),但我在控制台中没有看到任何错误指向正确的方向,但我的代码有问题:

<style type="text/css">

#outputOne{display: none;}
#outputTwo{display: none;}
#outputThree{display: none;}

</style>

</head>

<body>


<form method="POST" onsubmit="return showResults()">

    <input type="text" id="valueOne" /><br />
    <input type="text" id="valueTwo" /><br />
    <input type="text" id="valueThree" /><br />
    <input type="submit" id="submit" />

</form>

    <div id="outputOne">Value One</div>
    <div id="outputTwo">Value Two</div>
    <div id="outputThree">Value Three</div>


<script>

function showResults(){

    if(value <= 100){
    document.getElementById('outputOne').style.display = "block";
    return true;
    } if(value > 500){
    document.getElementById('outputTwo').style.display = "block";
    return true;
    }if(value > 10000){
    document.getElementById('outputThree').style.display = "block";
    return true;
    }
}

</script>

最佳答案

如果你想看到一些东西,你应该通过返回 false 而不是 true 来阻止提交,因为现在表单将在所有情况下提交,你永远不会看到显示的 div,因为页面将被刷新。

希望这对您有所帮助。

关于javascript - 提交时显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35689021/

相关文章:

javascript - 具有必需属性的vuejs-datepicker被提交但没有值(value)

javascript - 为什么我的 z-index 不起作用?

jquery - 不可见数据的打印问题

html - 通过其计算属性查找元素(例如范围内的位置和大小)

javascript - Uncaught Error : Invalid type for google table column

javascript - 在 AngularJS 中获取 JSESSIONID 值并创建 Cookie

javascript - 如何从 JavaScript 执行 EventListener 'click'

javascript - SVG 空间中foreignObject HTML 元素的坐标

javascript - 逐渐增加 eclipse 刻素描元素的不透明度

javascript - 查找适合多少个字母的div