让input框只能输入数字

var oInput = document.querySelector("input");
oInput.onkeyup = function () {
var value = this.value;
if(value.search(/^d+$/) != 0){
  this.value = value.replace(/[^0-9]/g,'');
  }
}

原文地址:https://www.cnblogs.com/toward-the-sun/p/4781079.html