<html><head></head><body><div></div><script>function remove(){ var mydiv=document.getElementsByTagName("div")[1]; if (mydiv) { mydiv.parentNode.removeChild(mydiv); } }function add(){ var div=document.getElementsByTagName("div")[0]; if (div) { var mydiv = document.createElement("div"); mydiv.style.height = "100px"; mydiv.style.background = getColor(); div.appendChild(mydiv); }} function getColor(){ var r=Math.floor(Math.random()*256); var g=Math.floor(Math.random()*256); var b=Math.floor(Math.random()*256); return "rgb("+r+','+g+','+b+")"; }</script><button onclick="remove()">remove red div</button><button onclick="add()">add green div</button></body></html>
打开App,阅读手记