js input 只能输入整数

JavaScript017

js input 只能输入整数,第1张

<el-input placeholder="请输入正整数" :min='1' type="number" oninput="value=value.replace(/[^\d]/g,'')" v-model="durationStart" ></el-input>

//:min='1' 最小值为1

【参考资料】1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">2.只能输入数字,能输小数点.<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"><input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字')this.value=''}">3.数字和小数点方法二<input type=text t_value="" o_value="" onkeypress="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/)){this.value=this.t_value } else {this.t_value=this.value }if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/)) {this.o_value=this.value"onkeyup="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/)) {this.value=this.t_value }else {this.t_value=this.value }if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/)) {this.o_value=this.value" onblur="if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/)){this.value=this.o_value }else if(this.value.match(/^\.\d+$/)) {this.value=0+this.value }if(this.value.match(/^\.$/)) {this.value=0 } this.o_value=this.value}">