for(var i=0;i<10;i++)
{
var testDv=document.createElement("div");
testDv.id="t"+i;
document.body.appendChild(testDv);
}
//查找
for(var i=0;i<10;i++)
{
var testDv=document.getElementById("t"+i);
testDv.innerHTML="找到第"+i+"个";
}
直接设置不行吗?
var oDiv= document.createElement('div');
oDiv.id = "myDiv";
Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
window.onload = function(){
var oDiv= document.createElement('div');
oDiv.id="ooDiv";
oDiv.innerHTML="hello";
document.body.appendChild(oDiv);
alert(document.getElementById("ooDiv").innerHTML);
}
</script>
</head>
<body>
</body>
</html>