利用jquery实现验证输入的是否是数字、小数,包含保留几位小数

1、验证方法 validationNumber(e,num) e代表标签对象,num代表保留小数位数

-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、验证整数

rush:js;"> Box ID="txtNg" name="txtNg" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,0)">

3、保留一位小数

rush:js;"> Box ID="txtChglinecost" name="txtChglinecost" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,1)">

4、保留两位小数

rush:js;"> Box ID="txtStdyr" name="txtStdyr" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,2)">

5、保留三位小数

  只需要把 validationNumber(this,3) 方法中的第二个参数改为3即可。

  保留四位小数、保留五位小数,以此类推...

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,同时也希望多多支持编程之家!

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...