簡體   English   中英

如果百分比不是數值,我該如何提醒用戶?

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

當值超出范圍時,我會提醒用戶:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM