js追加子元素
在页面加载完毕后,向div元素追加span子元素。
1 <html> 2 <head> 3 <title>js</title> 4 <script type="text/javascript"> 5 window.onload=function(){ 6 var div=document.getElementById("divid"); 7 var span=document.createElement("span"); 8 span.id="spanid"; 9 span.style.color="blue"; 10 span.innerHTML=" i am append span !" 11 div.appendChild(span); 12 } 13 </script> 14 </head> 15 <body> 16 <div id="divid" style="color: red; font-size:80;">i am div !</div> 17 </body> 18 </html>
if you don't try,you will never know!