1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div class="box"></div> <div class="root"></div> </body> </html> <script type="text/javascript"> var box=document.querySelector(".box"); var rot=document.querySelector('.root'); var img=document.createElement('img'); console.log(img,typeof img); box.appendChild(img); img.src="img/1.jpg";
var a=document.createElement("a"); a.href="http://www.baidu.com"; a.innerHTML="百度一下"; box.appendChild(a); var h2=document.createElement("h2"); h2.innerHTML="哈哈哈哈哈哈"; h2.style.backgroundColor="red"; box.insertBefore(h2,box.firstElementChild);
var h3=document.createElement("h3"); h3.innerHTML="周五了周五了"; box.replaceChild(h3,h2); box.removeChild(img);
</script>
|