标签:
1.页面
<asp:TextBox runat="server" ID="NumZYZCZMJ" OnKeyUp="InputFloat(this)"></asp:TextBox>
2.JS
//只能输入整数
function InputNumber(e) {
e.value = e.value.replace(/\D/g, "");
if (e.value.substring(0, 1) == "0") {
e.value = "0";
}
}
//只能输入浮点数 function InputFloat(e) {
e.value = e.value.replace(/[^\.\d]/g, "");
if (e.value.substring(0, 2) == "00") {
e.value = "0";
}
if (e.value.substring(0, 1) == ".")
{ e.value = ""; }
if (e.value.split(‘.‘).length == 2) {
e.value = e.value.split(‘.‘)[0] + ‘.‘ + e.value.split(‘.‘)[1].substring(0, 2); }
if (e.value.split(‘.‘).length > 2) { e.value = e.value.split(‘.‘)[0] + ‘.‘ + e.value.split(‘.‘)[1]; }
}
标签:
原文地址:http://www.cnblogs.com/nygsb2014/p/4198489.html