Html PHP 文本框长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1691342/
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
PHP Text Box Length
提问by The Woo
I'm playing with some PHP for my website. How do I set the length of a text box that the user types in? Also, what is the code for making multiple line text boxes?
我正在为我的网站使用一些 PHP。如何设置用户输入的文本框的长度?另外,制作多行文本框的代码是什么?
Thanks.
谢谢。
回答by Wayne Arthurton
I believe you really want to specify this in the HTML code as the maxlength
attribute in the text box.
我相信您真的想在 HTML 代码中将其指定为maxlength
文本框中的属性。
<input type="text" size="25" maxlength="25" value="Enter your name here!">
As for multilines, you want to set up a text area instead of a text box.
至于多行,你想设置一个文本区域而不是一个文本框。
<textarea name="comments">
</textarea>
The size
refers to the physical size of the box, where as the maxlength
refers to the input data length.
的size
指盒,其中作为的物理尺寸maxlength
是指输入数据长度。
Again, not PHP, but HTML.
同样,不是 PHP,而是 HTML。
As with all input, you should verify in your script that you are getting the length you expected.
与所有输入一样,您应该在脚本中验证您获得了预期的长度。
回答by jaywon
The length of a textbox is done with CSS rules or with the size attribute of the tag.
文本框的长度由 CSS 规则或标签的 size 属性决定。
ex. <input name="text" size="200" />
前任。 <input name="text" size="200" />
A multiple line text box is a <textarea></textarea>
HTML tag.
多行文本框是一个<textarea></textarea>
HTML 标记。
Neither of these have anything to do with PHP, but rather are simple HTML.
这些都与 PHP 无关,而是简单的 HTML。
回答by strager
The preferred method of specifying a "size" (i.e. character width) of an input box is to use the width
CSS property:
指定输入框“大小”(即字符宽度)的首选方法是使用width
CSS 属性:
<!-- HTML -->
<input type="text" style="width: 42em;" />
/* CSS */
#search {
width: 42em;
}
Multi-line text boxes are called text areasin HTML and the <textarea>
element represents them, as the other answers state.
多行文本框在 HTML中称为文本区域,<textarea>
元素代表它们,正如其他答案所述。
回答by aland
http://www.w3schools.com/TAGS/tag_textarea.asp
http://www.w3schools.com/TAGS/tag_textarea.asp
http://www.w3schools.com/TAGS/tag_input.asp
http://www.w3schools.com/TAGS/tag_input.asp
So with the part of it, I need to line it up on the same line of html to other boxes. But it needs to line up along the top, any suggestions for that?
因此,对于它的一部分,我需要将它与其他框的 html 同一行对齐。但它需要沿着顶部排列,有什么建议吗?
Not sure I understand, maybe you could show some code that illustrates the problem.
不确定我是否理解,也许您可以展示一些说明问题的代码。
I recommend to install the Web developer add-on for firefox, that way you can edit css directly and see the results! https://addons.mozilla.org/en-US/firefox/addon/60
我建议安装firefox的Web开发插件,这样你就可以直接编辑css并查看结果!https://addons.mozilla.org/en-US/firefox/addon/60
回答by davidg
In html use a <input type="text" size="25" maxlength="100">
for a single-line text field, and <textarea></textarea>
for multiple-line text boxes. size="25"
determines the number of characters that will be visible in the text field (in this case 25), and maxlength="100"
determines the maximum number of characters that a user can input into that field (in this case 100).
在 html 中,将 a<input type="text" size="25" maxlength="100">
用于单行文本字段和<textarea></textarea>
多行文本框。 size="25"
确定在文本字段中可见的字符数(在本例中为 25),并maxlength="100"
确定用户可以输入到该字段中的最大字符数(在本例中为 100)。