Textarea readOnly 属性

Textarea 对象参考手册 Textarea 对象

定义和用法

readOnly 属性设置或返回 textarea 是否为只读。

在只读文本区域,不能改变内容,但用户可以"选项卡"设置,或突出显示并复制它的内容。

语法

设置 readOnly 属性:

textareaObject.readOnly=true|false

返回 readOnly 属性:

textareaObject.readOnly

描述
true 指定文本区是只读
false 指定文本区域是可变。这是默认


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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


实例

实例

设置文本区域为只读:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("myTextarea").readOnly=true;
}
</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>

<button type="button" onclick="displayResult()">Make text area read-only</button>

</body>
</html>



Textarea 对象参考手册 Textarea 对象