<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title> <style>Div{width:300px;Height:300px;Border:1px solid Pink; } </style></Head><Body><inputtype= "button"value= "Create button"ID= "BT"/><DivID= "DV"></Div><Scriptsrc= "Common.js"></Script><Script> //There is delete, none is created //be responsible for deleting//my$ ("BT"). onclick = function () {////Determine if there is no such element in the DIV is deleted////Determine if the child element of this button exists//if (my$ ("BT2")) {//Is true there is//my$ ("DV"). RemoveChild (my$ ("BT2"));// }//var btobj = document.createelement ("input");//btobj.type = "button";//btobj.value = "button";//btobj.id = "BT2";//my$ ("DV"). AppendChild (btobj);// }; //None created //determine if there is no such element in the Div, none created //determine if the child element of this button existsmy$ ("BT"). onclick= function () { if(!my$ ("BT2")) { varBtobj=Document.createelement ("input"); Btobj.type= "Button"; Btobj.value= "Button"; Btobj.id= "BT2"; my$ ("DV"). appendchild (Btobj); } };</Script></Body></HTML>
JavaScript creates only one element, multiple clicks do not create