<input type="text" onkeydown="javascript:return isNumber(event,value);"/>
js部分:
<script> isNumber = function (e,s) { var t = 0; //只能输入一个小数点 if(s.indexOf(".") != -1){ t = 1; } if(t==1&&((event.keyCode == 190)||(event.keyCode == 110))){ return false; } //IE浏览器 if ($.browser.msie) { if ( ((event.keyCode > 47) && (event.keyCode < 58)) || ((event.keyCode > 95) && (event.keyCode < 106)) || (event.keyCode == 8 || (event.keyCode == 190) || (event.keyCode == 110))) { return true; } else { return false; } }else { if ( ((e.which > 47) && (e.which < 58)) || ((e.which > 95) && (e.which < 106)) || (e.which == 8)||(e.which == 110)||(e.which == 190)) { return true; } else { return false; } } return true; } </script>
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/14551.html