【发布时间】:2017-08-05 17:17:33
【问题描述】:
我对html页面中的简单代码getelementbyid.innerHtml感到震惊。请帮我。
<!doctype html>
<html lang="en">
<head>
<title>Dom examples</title>
<script>
var code = document.getElementById("one").innerHTML;
code = code + " !!";
console.log(code);
</script>
</head>
<body>
<h4> DOM practise page </h4>
<p id="one"> This page is for practise of DOM model in JS</p>
<p id="two"> Thank You </p>
</body>
</html>
【问题讨论】:
-
因为尚未加载 id=one 的元素
-
你试过
.innerText而不是.innerHTML吗?
标签: javascript html innerhtml getelementbyid