<html>
<body>
姓名: <input type="text" id="myText">
<p>点击按钮设置文本域只读。</p>
<p><strong>提示:</strong> 要查看效果,请尝试在点击按钮前后向文本域中输入信息。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
document.getElementById("myText").readOnly = "true";
}
</script>
</body>
</html>