SOURCE

console 命令行工具 X clear

                    
>
console
function num(target){
  var initVal, regexp = /^\d{1,}$/g,newVal;
  var type = Object.prototype.toString.call(target);
  if(type === '[object Object]'){
    // 传入的是jquery对象
    initVal = target.val();
    target.bind('input propertychange',function(){
      newVal = $(this).val();
      if(regexp.test(newVal)){
        newVal = +newVal;
        return;
      }else{
        $(this).val(initVal);
      }
    })
    return;
  }
   initVal = target.value;
    target.addEventListener('input propertychange',function(){
      newVal = this.value;
       if(regexp.test(newVal)){
        newVal = +newVal;
        return;
      }else{
        $(this).val(initVal);
      }
    })
}
var el = document.getElementById('num');
num(el);
<input type="tel" value = "1" id="num"/>