使用javascript检查数字范围

时间:2018-03-17 19:18:53

标签: javascript

我想使用Javascript检查并验证范围上的某些数字,例如(1到6)。 我尝试过解决方案一和二,但无法让它工作。

解决方案1 ​​

var num =9;
if (!in_array(num, 1,6)){
    alert('this number is not within the range);
} 

解决方案2

var num =9;
if (num =>1 && num <=6){
    alert('this number is okay);
} else{
    alert('this number is not within the range);
}

1 个答案:

答案 0 :(得分:0)

num&gt; = not num =&gt;

 var num =9;
        if (num >=1 && num <=6){
        alert('this number is okay');
        } else{
    alert('this number is not within the range');
    }