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

利用jquery實(shí)現(xiàn)驗(yàn)證輸入的是否是數(shù)字、小數(shù),包含保留幾位小數(shù)

 更新時(shí)間:2016年12月07日 16:25:08   作者:冷戰(zhàn)  
本文主要介紹了利用jquery實(shí)現(xiàn)驗(yàn)證輸入的是否是數(shù)字、小數(shù),包含保留幾位小數(shù),代碼清晰,容易理解。有需要的朋友可以參考下

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

function validationNumber(e, num) {
      var regu = /^[0-9]+\.?[0-9]*$/;
      if (e.value != "") {
        if (!regu.test(e.value)) {
          alert("請(qǐng)輸入正確的數(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、驗(yàn)證整數(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) 方法中的第二個(gè)參數(shù)改為3即可。

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

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論