maxlength 与 webkit 冲突

huangapple go评论69阅读模式
英文:

maxlength conflicting with webkit

问题

我在我的数字输入中添加了一个 maxlength 设置,它在我尝试移除侧边的数字箭头之前是有效的。它们是否以某种方式相互冲突?

<input type='number' id='numberInput' maxlength='16' placeholder='输入一个数字*'></input>

当我添加以下 CSS 时,它停止工作:

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
::-webkit-input-placeholder {
     text-align: center;
}
 :-moz-placeholder {
     text-align: center;
     -moz-appearance: text-field;
}

JSFiddle(已注释)供检查

英文:

I added a maxlength setting to my number input and it worked until I tried to remove the number arrows from the side. Do they somehow conflict with eachother?

<input type='number' id='numberInput' maxlength='16' placeholder='Enter a number*'></input>

It stopped working when I added this to the css

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
::-webkit-input-placeholder {
     text-align: center;
}
 :-moz-placeholder {
     text-align: center;
     -moz-appearance: text-field;
}

JSFiddle (commented) for inspection

答案1

得分: 1

maxlength不支持type="number"。如果切换到type="text",它将起作用,但在移动设备上,您将失去数字键盘作为第一个建议。

作为解决方法,尝试用onKeyPress="if(this.value.length==16) return false;"替换maxlenght="16"

英文:

maxlength is not supported by type="number". It would work if you switch to type="text", but on mobile devices you will lose the numerical keyboard as first suggestion.

As workaround, try to replace maxlenght="16" with onKeyPress="if(this.value.length==16) return false;",

huangapple
  • 本文由 发表于 2023年7月14日 08:15:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683976.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定