我在表单中使用number类型的输入,如下所示:
<input class="form-control" id="Parti_NEstudante" name="Parti_NEstudante" type="number" min="0" max="9999999999" step="1" oninput="(validity.valid)||(value='');">
当我插入该值时,如果我引入的位数超过10位,由于我实现的最大值,所有输入都会被擦除。
我的问题是,有没有可能只是阻止更多的数字,而不是擦除我的输入?就像输入类型text的maxlength行为一样。
发布于 2018-02-03 02:29:49
您可以通过这种方式实现这一点。
<input id="Parti_NEstudante" type="number" min="0" max="9999999999">
<script>
var input = document.getElementById("Parti_NEstudante");
input.addEventListener("input", function() {
if (this.value.length > this.max.length) {
this.value = this.value.slice(0, this.max.length)
}
});
</script>https://stackoverflow.com/questions/48588596
复制相似问题