js在html特定位置添加dom元素
<div id="d1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
var para=document.createElement("p");
var node=document.createTextNode("This is new.");
para.appendChild(node);
var element=document.getElementById("d1");
element.appendChild(para);
</script>
本文介绍如何使用JavaScript在HTML页面的指定位置动态添加新的DOM元素。通过创建新的`<p>`标签并设置其文本内容为Thisisnew.,然后将其插入到ID为d1的`<div>`中。

522

被折叠的 条评论
为什么被折叠?



