利用jquery实现验证输入的是否是数字、小数,包含保留几位小数
1、验证方法 validationNumber(e, num) e代表标签对象,num代表保留小数位数
function validationNumber(e, num) { var regu = /^[0-9]+.?[0-9]*$/; if (e.value != "") { if (!regu.test(e.value)) { alert("请输入正确的数字"); 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、验证整数
<asp:TextBox ID="txtNg" name="txtNg" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,0)"></asp:TextBox>
3、保留一位小数
<asp:TextBox ID="txtChglinecost" name="txtChglinecost" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,1)"></asp:TextBox>
4、保留两位小数
<asp:TextBox ID="txtStdyr" name="txtStdyr" runat="server" Height="16px" Width="98px" Font-Size="9pt" CssClass="EditTextBox" onpropertychange="validationNumber(this,2)"></asp:TextBox>
5、保留三位小数
只需要把 validationNumber(this,3) 方法中的第二个参数改为3即可。
保留四位小数、保留五位小数,以此类推...
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,同时也希望多多支持积木网!
DropDownList实现可输入可选择(两种版本可选)
1、js版本divstyle="z-index:0;visibility:visible;clip:rect(0px105px80px85px);position:absolute"asp:DropDownListID="ddlModel"runat="server"Style="z-index:-1"Width="105px"onchange="getModelTo(this)"as
获取select的value、text值的简单示例(jquery与javascript)
1、jquery//获取value值$("#ddlSubmodel").val();//获取text值$("#ddlSubmodel").find("option:selected").text();2、javascript//获取value值document.getElementById("ddlSubmodel").value;//获取tex
完美解决jQuery 鼠标快速滑过后,会执行多次滑出的问题
如果用slideToggle,鼠标快速滑过后,滑进滑出很多次,要解决这个问题,用stop(false,true)$(".Nav_L").hover(function(){$(".Cate2").stop(false,true).slideToggle(500);});以上
编辑:568数据
标签:小数,鼠标,滑过,滑出,本文