html文本区域标记,<textarea>

HTML 元素表示一个多行纯文本编辑控件,当你希望用户输入一段相当长的、不限格式的文本,例如评论或反馈表单中的一段意见时,这很有用。

上述例子展示了  的几个特点:

为了提高可访问性(accessibility),用于将 与一个  关联的 id 属性。

name 属性,用于设置随表单一同提交到服务器的相关数据的名字。

rows 和 cols 属性,用于声明  的精确尺寸。这对于一致性非常有帮助,因为不同浏览器的默认值常常不一样。

位于开始标签和闭合标签之间的默认内容。 不支持 value 属性。

 还可以使用  中的一些常见属性,如autocomplete, autofocus, disabled, placeholder, readonly, 和 required。

这个元素包含了全局属性。

iOS的非标准属性(运行在iOS上的Safari、Firefox、Chrome都支持),文本是否自动首字母大写。在iOS5和之后的版本上有效。可能的值为:

none: 禁用首字母大写。

sentences: 句子的首字母大写。

words: 单词或者字母的首字母大写。

characters: 全部字母大写。

on:  自iOS 5废弃。

off: 自iOS 5废弃。

是否使用浏览器的记忆功能自动填充文本。可能的值有:

off: 不使用浏览器的记忆自动填充,使用者必须输入他们想要输入的所有内容。或者网页提供了自己的自动填充方法。

on: 浏览器根据用户之前输入的内容或者习惯,在用户输入的时候给出相应输入提示。

如果不指明autocomplete属性,浏览器会从父级的表单元素上解析是不是开启这个属性。表单元素可以是`textarea`元素的父级

或者`textarea`有跟表单相同的id(参见下面的form属性)。更多请查看的autocomplete 属性。

页面加载完毕之后是否自动给本元素添加焦点。只有跟表格关联的才能使本属性生效。

文本域的可视宽度。必须为正数,默认为20 (HTML5)。

禁用文本域。默认为false。如果未指定,也可以从父级上如

继承而来。

指定跟自身相关联的表单。值必须为本文档内的表单的ID,如果未指定,就是跟当前所在的表单元素相关联。这就允许你在文档的任意地方放置文本域元素。

允许用户输入的最大字符长度 (Unicode) 。未指定表示无限长度。

允许用户输入的最小字符长度(Unicode)

元素的名称。

向用户提示可以在控件中输入的内容。 在渲染提示时,占位符文本中的回车符(\r)或换行符(\n)一定会被作为行断(换行)处理。

Note: Placeholders should only be used to show an example of the type of data that should be entered into a form; they are not a substitute for a proper element tied to the input. See Labels and placeholders in : The Input (Form Input) element for a full explanation.

不允许用户修改元素内文本。和 disabled 属性不同的是,这个能让用户点击和选择元素内的文本。如果在表单里,这个元素的值还是会跟随表单一起提交。

提示用户这个元素的内容必填。

元素的输入文本的行数(显示的高度)。

该属性设为true时,表明该元素会做拼写和语法检查。属性值为default时,表明元素有默认行为,可能会基于父元素的spellcheck值。属性值为false时,表明元素不做拼写和语法检查。

指定文本换行的方式。默认为soft。可能的值为:

hard: 在文本到达元素最大宽度的时候,浏览器自动插入换行符(CR+LF) 。比如指定 cols值。

soft: 在到达元素最大宽度的时候,不会自动插入换行符。

是 可被替换的元素——其有自己的固有尺寸,像。默认情况下,其 display 值为 block。与其他表单元素相比,这个元素相对比较容易设置样式,使用常规的 CSS 就可以轻松设置它的盒模型、字体、颜色方案等。

Styling HTML forms 这个页面提供了一些关于  样式的有用提示。

The HTML specification doesn't define where the baseline of a  is, so different browsers set it to different positions. For Gecko, the  baseline is set on the baseline of the first line of the textarea's first line, on another browser it may be set on the bottom of the  box. Don't use vertical-align: baseline on it; the behavior is unpredictable.

In most browsers, s are resizable — you'll notice the drag handle in the right hand corner, which can be used to alter the size of the element on the page. This is controlled by the resize CSS property — resizing is enabled by default, but you can explicitly disable it using a resize value of none:

textarea {

resize: none;

}

Valid and invalid values of a  element (e.g. those within, and outside the bounds set by minlength, maxlength, or required) can be highlighted using the :valid and :invalid pseudo-classes. For example, to give your textarea a different border depending on whether it is valid or invalid:

textarea:invalid {

border: 2px dashed red;

}

textarea:valid {

border: 2px solid lime;

}

Write something here

The following example show a very simple textarea, with a set numbers of rows and columns and some default content.

rows="10" cols="50">Write something here

This example has a minimum and maximum number of characters — of 10 and 20 respectively. Try it and see.

rows="5" cols="30"

minlength="10" maxlength="20">Write something here

Note that minlength doesn't stop the user from removing characters so that the number entered goes past the minimum, but it does make the value entered into the  invalid. Also note that even if you have a minlength value set (3, for example), an empty  is still considered valid unless you also have the required attribute set.

This example has a placeholder set. Notice how it disappears when you start typing into the box.

rows="5" cols="30"

placeholder="Comment text.">

Note: Placeholders should only be used to show an example of the type of data that should be entered into a form; they are not a substitute for a proper element tied to the input. See Labels and placeholders in : The Input (Form Input) element for a full explanation.

This example shows two s — one of which is disabled, and one of which is readonly. Have a play with both and you'll see the difference in behavior — the disabled element is not selectable in any way (and its value is not submitted), whereas the readonly element is selectable and its contents copyable (and its value is submitted); you just can't edit the contents.

Note: In browsers other than firefox, such as chrome, the disabled textarea content may be selectable and copyable.

rows="5" cols="30"

disabled>I am a disabled textarea

rows="5" cols="30"

readonly>I am a readonly textarea

Permitted content

Text

Tag omission

不允许,开始标签和结束标签都不能省略。

Permitted parents

Any element that accepts phrasing content.

Implicit ARIA role

Permitted ARIA roles

No role permitted

BCD tables only load in the browser

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值