<html>
<body>
<p id="myP" contenteditable="true">尝试修改文本。</p>
<button onclick="myFunction(this);">禁用文本可编辑!</button>
<p id="demo"></p>
<script>
function myFunction(button) {
var x = document.getElementById("myP");
if (x.contentEditable == "true") {
x.contentEditable = "false";
button.innerHTML = "启用 p 元素内容编辑!";
} else {
x.contentEditable = "true";
button.innerHTML = "禁用 p 元素内容编辑!";
}
}
</script>
</body>
</html>