Latest web development tutorials

HTML DOM Textarea readOnly property

Textarea Object Reference Textarea object

Definition and Usage

readOnly property sets or returns whether textarea as read-only.

In the read-only text area, you can not change the content, but the user can "tab" setting, or highlight and copy its contents.

grammar

Set readOnly properties:

textareaObject.readOnly=true|false

Back readOnly attributes:

textareaObject.readOnly

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support readOnly property


Examples

Examples

Is set to read-only text area:

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

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

<button type="button" onclick="displayResult()">设置 textarea 为只读</button>

</body>
</html>



Textarea Object Reference Textarea object