Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS-比较各个数值:_Javascript - Fatal编程技术网

Javascript JS-比较各个数值:

Javascript JS-比较各个数值:,javascript,Javascript,我正在评估一个数值和另一个数值之间是否满足条件,但我不知道如何添加单个值 这个例子对我很有用: $(document).ready(function(){ alertone(); }); $(document).on('input','#enviara',alertone); function alertone() { const total = Number($("#enviara").val().replace(".","")); if(total >= 52001

我正在评估一个数值和另一个数值之间是否满足条件,但我不知道如何添加单个值

这个例子对我很有用:

$(document).ready(function(){
  alertone();
});

$(document).on('input','#enviara',alertone);

function alertone() {
  const total = Number($("#enviara").val().replace(".",""));

  if(total >= 52001 && total <= 52006) {
    $("#alerta-melilla,.layer-melilla").show();
  }
  else{
    $("#alerta-melilla,.layer-melilla").hide();
  };
};
我尝试过这些片段,但对我来说不起作用:

if (total> = 52001 && total <= 52006 && 52009 && 52012 && 52019) { ...

如果(total>=52001&&total=52001&&total=52001&&total&total您可以创建一个包含要接受的异常值的
数组
,并检查
total
是否在该
数组
内:

let validValues = [ 52009, 52012, 52019 ];
if ((total >= 52001 && total <= 52006) || validValues.contains(total)) { /* ... */ }
让validvalue=[520095201252019];

如果((total>=52001&&total定义数组中的其他数字,并检查该数组中是否存在
total

const total = 100;
let otherNumbers = [100, 200];

const otherNumbersMatches = otherNumbers.find(num => num === total);

if ((total >= 52001 && total <= 52006) || otherNumbersMatches) {
  // do something
  console.log('Matches')
}
const总计=100;
让其他数字=[100200];
const otherNumbersMatches=otherNumbers.find(num=>num==total);

if((total>=52001&&total)您所说的“我还想检查各个值​​是写的吗?没有得到你的答案,请你解释一下你的想法好吗?正如你提到的:“但是在价值观之间。”​​52001和52006,我还想检查各个值​​写着:520095201252019“为什么52009/12/19介于52001和52006之间?首先,你有一个输入错误:
total>=
应该是
total>=
。应该是这样的。
如果(total>=52001&&total@TopWebGhost谢谢!好极了!)
if (total >= 52001 && total <= 52006 || total === 52009 || total === 52012 || total === 52019)
let validValues = [ 52009, 52012, 52019 ];
if ((total >= 52001 && total <= 52006) || validValues.contains(total)) { /* ... */ }
const total = 100;
let otherNumbers = [100, 200];

const otherNumbersMatches = otherNumbers.find(num => num === total);

if ((total >= 52001 && total <= 52006) || otherNumbersMatches) {
  // do something
  console.log('Matches')
}