87,921
社区成员
发帖
与我相关
我的任务
分享
<style>
.myclass {
text-align:left;
width:315px;
height:100px;
border: 1px solid #333333;
background:#FFFFCC;
padding:2px;
}
</style>
<body>
<div id="left_div1" style="border:#0066CC 1px solid; height:500; width:500;"></div>
<script>
//new div
var rss_div1=document.createElement("div");
//rss_div1.setAttribute("class","myclass");
rss_div1.className="myclass";
rss_div1.setAttribute("name","myname");
rss_div1.innerHTML="the string11";
var rss_div2=document.createElement("div");
//rss_div1.setAttribute("class","myclass");
rss_div2.className="myclass";
rss_div2.setAttribute("name","myname");
rss_div2.innerHTML="the string22";
//get father_div
var father_div=document.getElementById("left_div1");
//add
father_div.appendChild(rss_div1);
father_div.appendChild(rss_div2);
var list=document.getElementsByName("myname");
alert(list.length);
</script>
</body>