[英]Javascript conditional hiding and showing
Hello guys I'm confused with javascript code, I want a program that gets the input from the user, and if that input matches a specific value like 1234 I want it to hide part of the form. 大家好,我对javascript代码感到困惑,我想要一个程序来从用户那里获取输入,如果该输入与特定值(如1234)匹配,我希望它隐藏表单的一部分。 Eg
例如
var x=document.getElementById('pin').value; function hidden() { if (x.value=1234){ document.getElementById('pin').style.display="none"; } }
<input type="number" name="pin" placeholder="Please Enter Your Pin" id="pin"> <button onclick="hidden()">Enter</button>
var x=document.getElementById('pin'); function checkPin() { if (x.value == "1234"){ x.style.display="none"; } }
<input type="number" name="pin" placeholder="Please Enter Your Pin" id="pin" /> <button onclick="checkPin()">Enter</button>
The value is not a native number, but a string, and you're assigning in the conditional check. 该值不是本机数字,而是字符串,您将在条件检查中进行分配。 Instead of '=' use '==' or '==='.
代替“ =”,使用“ ==”或“ ===”。
Try this: 尝试这个:
function hidden() {
var x = document.getElementById('pin').value;
if (x === '1234'){
document.getElementById('pin').style.display = 'none';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.