js限制只能输入数字
$(document).on('keydown','input.count',onlyNum); $(document).on('keyup','input.count',notCn); function notCn(){ var reg = /^[0-9]*$/g; if(!(reg.test($(this).val()))){ $(this).val(''); } } function onlyNum(event){ var event = arguments[0]||window.event; if(!((event.keyCode>=48 && event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)) && event.keyCode != 8){ event.preventDefault(); } }