use*_*000 3 html javascript dom
我正在尝试创建一个动态创建一些元素的网页.我写了以下内容:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<p>Here's some example text</p>
<script type="text/javascript">
var jselem = document.createElement ("div");
jselem.innerHTML = '<p>and here\'s some more</p>';
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,JS部分似乎没有做任何事情,文本and here's some more没有打印.
谁能解释为什么它不起作用?任何帮助表示赞赏.
(请不要建议使用document.write()或类似.)
使用(小提琴)document.body.appendChild()
<script type="text/javascript">
var jselem = document.createElement("div");
jselem.innerHTML = '<p>and here\'s some more</p>';
document.body.appendChild(jselem);
</script>
Run Code Online (Sandbox Code Playgroud)