目标节点:
<div id="fnode"></div>
JS代码:
var div = document.getElementById("fnode");
var p = document.createElement("p");
p.innerHTML = '<font color="red">子节点</font>';
div.appendChild(p);
示例完整HTML代码:
<html>
<head>
<title>追加节点</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function addNode()
{
var div = document.getElementById("fnode");
var p = document.createElement("p");
p.innerHTML = '<font color="red">子节点</font>';
div.appendChild(p);
}
</script>
</head>
<body>
<input type="button" value="增加" οnclick="addNode()" />
<div id="fnode"></div>
</body>
</html>