您的位置:首页 > 其它

String.fromCharCode妙用只能input输入正数

2016-05-31 11:31 232 查看
type 可以是任何类型

$('input[type=score]').keypress(function(e) {

  if (!String.fromCharCode(e.keyCode).match(/[0-9\.]/)) {

    return false;

  }
});

兼容火狐用这个

$('input[type=score]').keypress(function(e) {

    if (e.which==8) {

      $(this).val('');

    };

 if (!String.fromCharCode(e.which).match(/[0-9\.]/)) {
   return false;
 }
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: