欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS驗證輸入的是否是數(shù)字及保留幾位小數(shù)問題

 更新時間:2018年05月09日 14:41:23   作者:冷戰(zhàn)  
這篇文章主要介紹了JS驗證輸入的是否是數(shù)字及保留幾位小數(shù)問題,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧

1、驗證方法 validationNumber(e, num)  e代表標(biāo)簽對象,num代表保留小數(shù)位數(shù)

function validationNumber(e, num) {
      var regu = /^[0-9]+\.?[0-9]*$/;
      if (e.value != "") {
        if (!regu.test(e.value)) {
          alert("請輸入正確的數(shù)字");
          e.value = e.value.substring(0, e.value.length - 1);
          e.focus();
        } else {
          if (num == 0) {
            if (e.value.indexOf('.') > -1) {
              e.value = e.value.substring(0, e.value.length - 1);
              e.focus();
            }
          }
          if (e.value.indexOf('.') > -1) {
            if (e.value.split('.')[1].length > num) {
              e.value = e.value.substring(0, e.value.length - 1);
              e.focus();
            }
          }

        }
      }
    }

2、驗證整數(shù)

<asp:TextBox ID="txtNg" name="txtNg" runat="server" Height="16px" Width="98px" Font-Size="9pt"
   CssClass="EditTextBox" onpropertychange="validationNumber(this,0)"></asp:TextBox>

3、保留一位小數(shù)

<asp:TextBox ID="txtChglinecost" name="txtChglinecost" runat="server" Height="16px" Width="98px" Font-Size="9pt" 
   CssClass="EditTextBox" onpropertychange="validationNumber(this,1)"></asp:TextBox>

4、保留兩位小數(shù)

<asp:TextBox ID="txtStdyr" name="txtStdyr" runat="server" Height="16px" Width="98px" Font-Size="9pt" 
   CssClass="EditTextBox" onpropertychange="validationNumber(this,2)"></asp:TextBox>

5、保留三位小數(shù)

  只需要把 validationNumber(this,3) 方法中的第二個參數(shù)改為3即可。

  保留四位小數(shù)、保留五位小數(shù),以此類推...

總結(jié)

以上所述是小編給大家介紹的JS驗證輸入的是否是數(shù)字及保留幾位小數(shù)問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論