JavaScript可以';让孩子去工作
我正在尝试将链接附加到我的html文档。它可以在JSFIDLE中工作,但不能与html文档和js文件一起工作。谁能看看我做错了什么JavaScript可以';让孩子去工作,javascript,dom,appendchild,Javascript,Dom,Appendchild,我正在尝试将链接附加到我的html文档。它可以在JSFIDLE中工作,但不能与html文档和js文件一起工作。谁能看看我做错了什么 <body> <div id="container"> <div id="content"> <p>hello</p> </div> </div> </body> </html> 小提琴: <body> <
<body>
<div id="container">
<div id="content">
<p>hello</p>
</div>
</div>
</body>
</html>
小提琴:
<body>
<div id="container">
<div id="content">
<p>hello</p>
</div>
</div>
</body>
</html>
HTML代码:
Javascript隐藏文本区
<body>
<div id="container">
<div id="content">
<p>hello</p>
</div>
</div>
</body>
</html>
创建文本节点的意义是什么?只需设置innerHTML
<body>
<div id="container">
<div id="content">
<p>hello</p>
</div>
</div>
</body>
</html>
var test= document.getElementById("content");
var a = document.createElement("a");
a.href = "#"
a.innerHTML = "länk";
test.appendChild(a);
另外,脚本标记在哪里?如果您没有使用
窗口.onload
侦听器,则应将脚本标记添加为正文中的最后一项
确保DOM已准备就绪。我有一个脚本标记,但最后一行js代码似乎有问题。
<body>
<div id="container">
<div id="content">
<p>hello</p>
</div>
</div>
</body>
</html>