我有一个带有type="number"的input标记,我正在使用最大长度来限制输入长度。它在所有浏览器上都工作得很好,但当我在三星手机上使用它时,最大长度不起作用。否则,在配备google键盘和ios键盘的设备上,max-length就可以了。
$(".numeric").on("input keypress", function () {
this.value = this.value.replace(/[^0-9]/g, "");
if (this.value.length == 3) return false;
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" class="numeric" max="999" />
发布于 2020-08-28 14:07:34
$(".numeric").on("input keypress", function () {
this.value = this.value.replace(/[^0-9]/g, "");
if (this.value.length > 3){
this.value= this.value.substring(0,3);
};
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" class="numeric" max="999" />
https://stackoverflow.com/questions/63628220
复制相似问题