js判断是否整数,重程的写法,确定不能判断形如1.2的小数
<input id="e_num" onfocus="txtBoxfocus(this);" onchange="intCheck(this);" type="text" value="0" />
//=====================================校验====================================
//===================================输入格式校验==================================
var initVal = null;
// textBox onfocus
function txtBoxfocus(txtBox) {
initVal = txtBox.value;
};
// int input check
function intCheck(txtBox) {
if (!isPositiveInt(txtBox.value) || Number(txtBox.value) <= 0) {
alert('请输入整数!');
resetTxtBoxVal(txtBox);
return false;
}
return true;
};
String.prototype.IsPositiveInt=function()
{
var str=this;
var result = str.match(/^[1-9]\d*|0$/)
return result==null? false : true;
}
function resetTxtBoxVal(txtBox) {
txtBox.value = initVal;
};
浙公网安备 33010602011771号