Textarea cols attribute
Definition and Usage
cols
Attribute to set or return the value of the text area's cols attribute.
The HTML cols attribute specifies the visible width of the text area in characters.
Tip:You can also use style.width Attribute to set the width of the text area.
Tip:Use rows Attribute or style.height Attribute to change the height of the text area.
See also:
HTML Reference Manual:HTML <textarea> cols 属性
Example
Example 1
Change the width of the text area:
document.getElementById("myTextarea").cols = "100";
Example 2
Get the width of the text area in characters:
var x = document.getElementById("myTextarea").cols;
Example 3
Change the width of the text area using the style.width attribute:
document.getElementById("myTextarea").style.width = "500px";
Example 4
Use cols and rows attributes to change the width and height of the text area:
document.getElementById("myTextarea").cols = "100"; document.getElementById("myTextarea").rows = "10";
Example 5
Use style.width and style.height attributes to change the width and height of the text area:
document.getElementById("myTextarea").style.width = "500px"; document.getElementById("myTextarea").style.height = "100px";
Syntax
Return cols attribute:
textareaObject.cols
Set cols attribute:
textareaObject.cols = number
属性值
值 | 描述 |
---|---|
number | 规定文本区域的宽度(以平均字符宽度计)。默认值为 20。 |
技术细节
返回值: | 数值,表示文本区域的宽度,以字符为单位。 |
---|
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |