html 的输入字段中可能有多少个字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3107999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how many characters are possible in an input field in html?
提问by helle
What is the "natural" number of allowed characters in an input field in html?
html 输入字段中允许的“自然”字符数是多少?
thanks a lot
多谢
addition due to the comments
由于评论而补充
i don't need to send it to the server via post or get. i am going to parse the string via JS.
我不需要通过邮寄或获取将它发送到服务器。我将通过 JS 解析字符串。
So if the input is unlimited like @sAc says brings me to two further questions:
因此,如果输入是无限的,就像@sAc 所说的那样,会给我带来两个进一步的问题:
- What is the longest String JS can handle?
- what is the lowest amount of allowed characters for an input in common browsers?(which would be my limit than)
- JS 可以处理的最长 String 是多少?
- 常见浏览器中输入的最少允许字符数是多少?(这将是我的限制)
回答by Samuel Neff
Firefox 3.6.6 on my 32 bit Win 7 machine becomes slow after 1,000,000 characters and totally freezes after 4,000,000.
我的 32 位 Win 7 机器上的 Firefox 3.6.6 在 1,000,000 个字符后变慢,在 4,000,000 个字符后完全冻结。
Chrome crashes somewhere after 8,000,000.
Chrome 在 8,000,000 之后崩溃。
IE8 crashes somewhere after 8,000,000.
IE8 在 8,000,000 之后某处崩溃。
Safari crashes somewhere after 2,000,000.
Safari 在 2,000,000 之后的某个地方崩溃。
In my testing Chrome/IE8/Safari don't slow down as the size goes up the way Firefox does.
在我的测试中,Chrome/IE8/Safari 不会像 Firefox 那样随着大小的增加而变慢。
回答by Sarfraz
When the type attribute has the value "text" or "password", this attribute specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimitednumber.
当 type 属性的值为“text”或“password”时,该属性指定用户可以输入的最大字符数。这个数字可能会超过指定的大小,在这种情况下,用户代理应该提供滚动机制。此属性的默认值是 无限数量。
Source: http://www.w3.org/TR/html401/interact/forms.html#adef-maxlength
资料来源:http: //www.w3.org/TR/html401/interact/forms.html#adef-maxlength
回答by Sam
I wouldn't think there is a limit, unless the code has something stopping it (size parameter) or the server can't take any more characters (either a LOT of characters or a bad server).
我不认为有限制,除非代码有阻止它的东西(大小参数)或服务器不能接受更多字符(很多字符或坏服务器)。
There is also the 32bit etc. limits depending on the server, I believe.
我相信,根据服务器的不同,还有 32 位等限制。
回答by Fidi
I think that depends on the method you are sending the form with. If you send the form via GET-method it's only 255 chars for the whole query (correct me if I am wrong). The POST-method allows much more...
我认为这取决于您发送表单的方法。如果您通过 GET 方法发送表单,则整个查询只有 255 个字符(如果我错了,请纠正我)。POST 方法允许更多...
So in the end you can write millions of chars in a text-field, the question is, if all chars are sent to the server.
所以最后你可以在一个文本字段中写入数百万个字符,问题是,如果所有的字符都发送到服务器。
In HTML however you've got the possibility to specify how many characters you want to allow. Look at this snippet:
但是,在 HTML 中,您可以指定要允许的字符数。看看这个片段:
<input type="text" name="email" maxlength="255" />
The maxlength
-attribute of the tag, prevents the user from being able to type in more than 255 chars.
maxlength
标签的 -属性防止用户输入超过 255 个字符。
回答by Hans Ke?ing
In a textarea you can enter an unlimited amount of text.
在文本区域中,您可以输入无限量的文本。
OK, in practice you shouldn't enter megabytes of text or you will run into server limits.
好的,实际上您不应该输入兆字节的文本,否则会遇到服务器限制。
When you the POST method to send the form to the server (which is the usual way), then you can send at least megabytes. When you use the GET method, the whole form is transferred through the querystring and there the limits are in the thousands of characters (the exact value depends on the server and the browser).
当您使用 POST 方法将表单发送到服务器时(这是通常的方式),那么您至少可以发送兆字节。当您使用 GET 方法时,整个表单通过查询字符串传输,并且限制在数千个字符内(确切值取决于服务器和浏览器)。
回答by Jochem Schulenklopper
The number of visible characters is dependent on the size of the input
element, but also on the style of that element: a wide box put in a shallow container (e.g., a div
or form
) will not show all the characters in the field.
可见字符的数量取决于input
元素的大小,还取决于该元素的样式:放在浅容器(例如 adiv
或form
)中的宽框不会显示该字段中的所有字符。
See W3Schools explanation on INPUT, paying attention to size
and maxlength
attributes. maxlength
specifies the maximum length (in characters) of an input field for "text" or "password" types, size
specifies the width of an input field.
参见W3Schools 对 INPUT 的解释,注意size
和maxlength
属性。maxlength
指定“文本”或“密码”类型的输入字段的最大长度(以字符为单位),size
指定输入字段的宽度。