87,910
社区成员
发帖
与我相关
我的任务
分享
var s1=document.createElement("div");
s1.firstChild.nodeValue="asd";
document.getElementById("div1").appendChild(s1);
<body>
<div id="div1">
</div>
</body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="JavaScript">
function addNode(){
var s1 = document.createElement("div");
s1.innerHTML = "asd";
document.getElementById("div1").appendChild(s1);
}
</script>
<body>
<input type="button" value="append" onclick="addNode();">
<hr>
<div id="div1">
</div>
</body>
</html>
<html>
<head runat="server">
<title>无标题页 </title>
<script type="text/javascript">
function Add(){
var s1=document.createElement("div");
//s1.firstChild.nodeValue="asd";//s1并没有firstChild,所以设置nodeValue这句出错了
//====>
s1.innerHTML="asd";
document.getElementById("div1").appendChild(s1);
}
</script>
</head>
<body>
<div id="div1"></div>
<input type="button" onclick="Add()" value="添加" />
</body>
</html>