IE is not very good, in IE setattribute only to recognize some static properties, and like the onclick event is invalid, to use the Attchevent method
<ptml> <pead> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title> Untitled document </title> </pead> <script type=" Text/javascript "> var elemen tcount=0; function Mycreateelement (element,tag) {elementcount++; var parentelement=element; var Count=elementcount; var childelement=document.createelement (tag); SetProperty (childelement, "type", "text"); SetProperty (childelement, "id", "input" + Elementcount) var delelement=document.createelement ("input"); SetProperty (delelement, "type", "button"); SetProperty (delelement, "value", "delete"); SetProperty (delelement, "id", "Delbutton" + elementcount) if (navigator.appname== "Microsoft Internet Explorer") del Element.attachevent ("onclick", function () {del (count)}) Else SetProperty (delelement, "onclick", "del" + Elementcoun T + ")"); var wrap=document.createelement (' div ') setProperty (wrap, "id", "div" + elementcount) wrap.aPpendchild (childelement); Wrap.appendchild (delelement); Parentelement.appendchild (Wrap)} function SetProperty (element,tag,property) {var element1=element; Element1.setattribute (Tag,property); } function del (elementCount1) {var Parentnode=document.getelementbyid ("Mycontent"); var Divnode=document.getelementbyid ("div" +elementcount1); Parentnode.removechild (Divnode); } </script> <body> <div id= "mycontent" > </div> <input type= "button" value= "Add" onclick= "my CreateElement (document.getElementById (' mycontent '), ' input ') ' > </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]