JS无法让我的真/假函数仅显示真输出

JS can't get my true/false function to display the false output only the true output

本文关键字:函数 显示 输出 我的 JS      更新时间:2023-09-26

我需要写一个好东西来验证一个数字是否在两个数字的范围内,无论我在文本框中输入什么,我都只能得到这个数字是有效的输出。

 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;
 }

而不是

if (output = true)

只是做

if (output)

if (output == true)

=用于分配,而=====用于比较。