String.fromCharCode方法可以使在input里只输入正整数,如下
$("#jq-buyNumber").keypress(function(e){
if(!String.fromCharCode(e.keyCode).match(/[0-9.]/)){
layer.msg("输入的数量不正确");
floa = false;
return false;
}
});
但是在火狐却是不兼容的,解决方法如下:
$("#jq-buyNumber").keypress(function(e){
if (e.which==8) {
$(this).val('');
};
if (!String.fromCharCode(e.which).match(/[0-9.]/)) {
layer.msg("输入的数量不正确");
floa = false;
return false;
}
});