如果它不是百分比的数值,我如何提醒用户?

How do i alert the user if it is not numeric value for percentage?

本文关键字:何提醒 用户 百分比 如果      更新时间:2023-09-26

当值越界时提醒用户:

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

但是我想首先检查value是否是一个有效的数字,我该怎么做呢?

使用isNaN函数,如果参数不是数字则返回true,如果参数是数字则返回false

if(isNaN(document.myForm.outputPercentage.value )){
alert('not a valid input');
 }