当值超出范围时,我会提醒用户:
if (document.myForm.outputPercentage.value <= 0 || document.myForm.outputPercentage.value >= 100)
{
alert( "Percentage output must be between 1 - 100" )
document.myForm.deviceId.focus() ;
return false;
}
但我想首先检查值是否是有效数字,我该怎么做?
最佳答案
使用 isNaN 函数,如果参数不是数字则返回 true,如果参数是数字则返回 false
if(isNaN(document.myForm.outputPercentage.value )){
alert('not a valid input');
}
关于javascript - 如果不是百分比数值,我如何提醒用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30524393/