[英]How to add condition for showing div in javascript
I tried adding condition in Javascript for div show:hide in HTML5 我尝试在Javascript中为div show添加条件:隐藏在HTML5中
#demo {
width: 500px;
height: 500px;
background-color: lightblue;
display: none;
}
Insert value between 0-9 to set function 插入0-9之间的值以设置功能
<input id="num" type="text" name="txt1">
<button onclick="myFunction()">Check</button>
<div id="demo">This is my Demo element.</div>
<div id="qwe"></div>
<script>
function myFunction() {
var num;
num = document.getElementById("num").value;
if (a < 10) {
document.getElementById("demo").style.display = "inline"; }
else { document.getElementById("qwe").innerHTML = "Not a Valid Number";
}
}
</script>
Am I wrong in the condition part 我错了条件部分
You used undefined variable "a" 你使用了未定义的变量“a”
if (a < 10) {
you have to change it to: 你必须改为:
if (num < 10) {
try this code: 试试这段代码:
<input id="num" type="text" name="txt1"> <button onclick="myFunction()">Check</button> <div id="demo">This is my Demo element.</div> <div id="qwe"></div> <script> function myFunction() { var num; num = document.getElementById("num").value; if (num < 10) { document.getElementById("demo").style.display = "inline"; document.getElementById("qwe").innerHTML = ""; } else { document.getElementById("qwe").innerHTML = "Not a Valid Number"; document.getElementById("demo").style.display = "none"; } } </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.