function regInput(obj, reg, inputStr) {
if (obj.readOnly != true) {
var docSel = document.selection.createRange();
if (docSel.parentElement().tagName != "INPUT")
return false; oSel = docSel.duplicate();
oSel.text = ""; var srcRange = obj.createTextRange();
oSel.setEndPoint("StartToStart", srcRange); var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
return reg.test(str);
}
else {
return true;
}
}
function MastInt(obj) {
return regInput(obj, /^[0-9]*$/, String.fromCharCode(event.keyCode));
} <asp:TextBox ID="txt_Amount" runat="server" Width="160px" MaxLength="10" Style="ime-mode: disabled" onkeypress="return MastDecimal(this);"></asp:TextBox>
现在只能输入整数 我要改成 只能输入整数或最多带2位小数的,一位当然也可以。 .请问下 我那个2段JS 怎么改。主要还是正则不会。
if (obj.readOnly != true) {
var docSel = document.selection.createRange();
if (docSel.parentElement().tagName != "INPUT")
return false; oSel = docSel.duplicate();
oSel.text = ""; var srcRange = obj.createTextRange();
oSel.setEndPoint("StartToStart", srcRange); var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
return reg.test(str);
}
else {
return true;
}
}
function MastInt(obj) {
return regInput(obj, /^[0-9]*$/, String.fromCharCode(event.keyCode));
} <asp:TextBox ID="txt_Amount" runat="server" Width="160px" MaxLength="10" Style="ime-mode: disabled" onkeypress="return MastDecimal(this);"></asp:TextBox>
现在只能输入整数 我要改成 只能输入整数或最多带2位小数的,一位当然也可以。 .请问下 我那个2段JS 怎么改。主要还是正则不会。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货