简体   繁体   English

不同浏览器中maxLength输入的默认值

[英]Default value of maxLength input in different browsers

I have a basic input tag with no maxlength attribute defined: <input id="foo" type="text" /> 我有一个没有定义maxlength属性的基本输入标记: <input id="foo" type="text" />

Trying to get the maxlength attribute in different browsers with the code document.getElementById("foo").maxLength returns the following values: 尝试使用代码document.getElementById("foo").maxLength获取不同浏览器中的maxlength属性document.getElementById("foo").maxLength返回以下值:

  • Chrome(73), Edge: -1 Chrome(73),Edge:-1
  • IE(11): 2147483647 IE(11):2147483647

 console.log(document.getElementById("foo").maxLength); 
 <input id="foo" type="text"/> 

Why is this happening if the default value of maxlenght is 524288 according to https://www.w3schools.com/tags/att_input_maxlength.asp ? 根据https://www.w3schools.com/tags/att_input_maxlength.asp,如果maxlenght的默认值为524288,为什么会发生这种情况?

I don't know for sure, but I believe that if no maxlength is set on the input, the default is actually unlimited. 我不确定,但我相信如果输入上没有设置maxlength ,默认实际上是无限制的。 This is then applied by the browser and is specific to the platform. 然后,这将由浏览器应用,并且特定于平台。 The W3schools link mentions 512KB as the maximum but that was presumably a value applied by specific browsers. W3schools链接提到512KB作为最大值,但这可能是特定浏览器应用的值。

References: What is the default maximum length of html input \\ text area? 参考: html输入\\文本区域的默认最大长度是多少?

Edit: just checked https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text and correctly there is no default maxlength, so Chrome and Edge are reporting that correctly. 编辑:刚刚检查了https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text,并且没有默认的maxlength,因此Chrome和Edge正确报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何基于AngularJS中不同的组合框值在输入字段上设置maxlength? - How to set maxlength on input field based on a different combo box value in AngularJS? 移动浏览器上的HTML5输入日期默认值行为 - HTML5 input date default value behavior on mobile browsers 一旦达到 maxlength 值,就聚焦下一个输入 - Focus next input once reaching maxlength value javascript将输入值填充为0,直到maxlength - javascript fill input value with 0's till maxlength 如何为适用于html 5浏览器和较旧浏览器的type = date输入设置默认值 - How to set a default value for a type=date input that works with html 5 browsers and with older browsers 在移动浏览器上强制执行 maxlength 属性 - Enforcing the maxlength attribute on mobile browsers 一旦在不同容器中达到最大长度,就集中关注下一个输入 - Focus next input once reaching maxlength in different containers 防止数字输入的 maxLength 不断改变最后一个数字的值? - Prevent maxLength on number input from constantly changing value on last number? 一旦达到最大长度值,请关注下一个输入 - reactjs - Focus next input once reaching maxlength value - reactjs 闪电输入中的 LWC 设置值和 maxlength=“99” 不起作用 - LWC set value in lightning-input and maxlength=“99” does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM