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')
}