源代码:
下载代码
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <textarea id="myTextarea"> Runoob</textarea> <p>点击按钮设置文本框 textarea 为只读。</p> <p><b>提示:</b> 点击按钮后尝试在文本框输入内容是无法写入的。 </p> <button type="button" onclick="myFunction()">点我</button> <script> function myFunction() { document.getElementById("myTextarea").readOnly = "true"; } </script> </body> </html>
运行结果: