js处理数字输入配合键盘控制
// 最大长度5,只能输入正整数 if (val.length > 1 && val[0] == 0) { // val = val.replace("/0", "/"); //这个是处理数字的,这里不适应 val = val.substr(1); } if (val.length > 5) { val = val.slice(0, 5); } console.log(val); val = val.replace(/[^0-9]/gi, "");
只能输入数字和+
val=va.replace(/[^\d^\+]/,'')" //type=number就限制不了中文+
<el-input type="number" v-model.number="scope.row.newquotaObj.quotaScore" size="small" @input="(val) => changInput(val, scope.row, scope.$index)" @keydown.native="channelInputLimit" ></el-input>
channelInputLimit(e) { let key = e.key; // 不允许输入'e'和'.' if (key === "e" || key === "." || key === "-" || key === "+") { e.returnValue = false; return false; } return true; },