这是我的代码,我该如何解决?当我使用firfox时,输入数字的字段无法通过退格按钮删除任何数字
function validateValue(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[0-9]|\./;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault)
theEvent.preventDefault();
}
}
<div class="amountWrap"><span> CHf </span>
<input min="1" max="99000" onkeypress="validateValue(event)" class="form-control input-lg input-ammount valid" id="single_amount_other" name="single_amount_other" placeholder="Andere Menge" aria-invalid="false" type="number">
</div>
答案 0 :(得分:0)
将正则表达式模式更改为:
var regex = /[0-9\b]|\./;