简体   繁体   中英

Default value of maxLength input in different browsers

I have a basic input tag with no maxlength attribute defined: <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:

  • Chrome(73), Edge: -1
  • 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 ?

I don't know for sure, but I believe that if no maxlength is set on the input, the default is actually unlimited. 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.

References: What is the default maximum length of html input \\ text area?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM