[英]JS can't get my true/false function to display the false output only the true output
I need to write a good that will validate if a number is in between a range of two numbers I can only get the number is valid output no matter what i input in my text box. 我需要编写一种商品来验证数字是否在两个数字之间,无论我在文本框中输入什么内容,我都只能得到该数字的有效输出。
function validInputRange(min, max, textbox) {
if (textbox >= min && textbox <= max) {
return true;
} else {
return false;
}
}
function btnValidate_onclick() {
// assign textbox elements to variables for easier access
var numberTextbox = document.getElementById("txtNumber");
var input = parseFloat(numberTextbox.value);
var output = validInputRange(1, 49, numberTextbox.value);
if (output = true) {
var answer = "valid";
numberTextbox.style.backgroundColor = "#00ff00";
} else {
answer = "false";
numberTextbox.style.backgroundColor = "#ff0000";
}
numberTextbox.value = answer;
}
Instead of 代替
if (output = true)
Just do 做就是了
if (output)
or 要么
if (output == true)
=
is used for assignment, while ==
or ===
for comparing. =
用于分配,而==
或===
用于比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.