Textarea cols 属性

Textarea 对象参考手册 Textarea 对象

定义和用法

cols 属性设置或返回文本框的字符列的宽度。

语法

设置 cols 属性:

textareaObject.cols="number"

返回 cols 属性:

textareaObject.cols

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


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流浏览器都支持 cols 属性


实例

实例

下面的例子更改的文本框的宽度:

<html>
<head>
<script>
function displayResult()
{
var textarea=document.getElementById("myTextarea");
textarea.cols=document.getElementById("myInput").value;
}
</script>
</head>
<body>

<textarea id="myTextarea" cols="20">
At W3CSchool you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP.
</textarea>
<br>

<p>Set cols attribute value: <input type="text" id="myInput" value="60">
<button type="button" onclick="displayResult()">Change cols attribute</button></p>

</body>
</html>



Textarea 对象参考手册 Textarea 对象