HTML DOM readOnly 属性

定义和用法

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

语法

  1. textareaObject.readOnly=true|false

实例

本例把 textarea 设置为只读:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function setReadOnly()
  5. {
  6. document.getElementById('txt1').readOnly=true;
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <textarea id="txt1">
  13. Hello world....This is a text area
  14. </textarea>
  15. <br />
  16. <input type="button" onclick="setReadOnly()"
  17. value="Make read-only" />
  18.  
  19. </body>
  20. </html>