HTML DOM Textarea cols 属性

Textarea cols 属性

Textarea 对象参考手册 Textarea 对象

实例

修改 textarea 元素的宽度:


document.getElementById("myTextarea").cols = "100";

知识兔 »

定义和用法

cols 属性用于设置或返回 cols 属性的值。

cols 属性指定文本框的宽度,以字符为单位。

提示: 你可以使用 style.width 属性来设置 textarea 元素的宽度。

提示: 你可以使用 rowsstyle.height 属性来设置 textarea 元素的宽度和高度。


浏览器支持

属性
cols Yes Yes Yes Yes Yes

语法

设置 cols 属性:

textareaObject.cols = number

返回 cols 属性:

textareaObject.cols

属性值

描述
number

指定文本框的宽度。默认为20。


技术细节

返回值: 一个数字,表示文本框的宽度,以字符为单位。

更多实例

实例

使用 style.width 属性修改宽度::


document.getElementById("myTextarea").style.width = "500px";

知识兔 »

实例

使用 textarea 元素的 cols 和 rows 属性修改高度和宽度:


document.getElementById("myTextarea").cols = "100";
document.getElementById("myTextarea").rows = "10";

知识兔 »

实例

使用 style.width 和 style.height 属性修改宽度和高度:


document.getElementById("myTextarea").style.width = "500px";
document.getElementById("myTextarea").style.height = "100px";

知识兔 »

Textarea 对象参考手册 Textarea 对象

计算机