function filterInt(evt){
evt = evt || window.event;
var b = evt.keyCode || evt.which;
return(b>=48&&b<=57)||b==44||b==45;
}
function filterFloat( evt ){
evt = evt || window.event;
var b = evt.keyCode || evt.which;
var _el = evt.srcElement || evt.target;
if( b == 46 ){
var _val = _el.value;
if( _val == "" || _val.split(".").length == 2 ){
return false;
}
}
return(b>=48&&b<=57)||b==44||b==45||b==46;
}
限制输入整型: <input type="text" οnkeypress="return filterInt(event);"/>
限制输入浮点型: <input type="text" οnkeypress="return filterFloat(event);"/>
转自:piziwang
evt = evt || window.event;
var b = evt.keyCode || evt.which;
return(b>=48&&b<=57)||b==44||b==45;
}
function filterFloat( evt ){
evt = evt || window.event;
var b = evt.keyCode || evt.which;
var _el = evt.srcElement || evt.target;
if( b == 46 ){
var _val = _el.value;
if( _val == "" || _val.split(".").length == 2 ){
return false;
}
}
return(b>=48&&b<=57)||b==44||b==45||b==46;
}
限制输入整型: <input type="text" οnkeypress="return filterInt(event);"/>
限制输入浮点型: <input type="text" οnkeypress="return filterFloat(event);"/>
转自:piziwang