Latest web development tutorials

HTML DOM Textarea cols attribute

Textarea Object Reference Textarea object

Definition and Usage

cols property sets or returns the text box character column width.

grammar

Setting cols attributes:

textareaObject.cols="number"

Back cols attributes:

textareaObject.cols

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support cols attribute


Examples

Examples

The following example changes the width of the text box:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult()
{
    var textarea=document.getElementById("myTextarea");
    textarea.cols=document.getElementById("myInput").value;
}
</script>
</head>
<body>

<textarea id="myTextarea" cols="20">
在本教程,你可以学多很多编程的基础知识,包括 HTML, XML, SQL, ASP, 和 PHP 等各种前端内容。
</textarea>
<br>

<p>设置 cols 属性值:<input type="text" id="myInput" value="60">
<button type="button" onclick="displayResult()">修改 cols 属性</button></p>

</body>
</html>



Textarea Object Reference Textarea object