Js instances: & amp; lt; html & amp; gt; & amp; lt; head & amp; gt; & amp; lt; title & amp; gt; php point-by-point-Follow php development and provide professional web development tutorials & amp; lt;/title & amp; gt;
The js instance is as follows:
Php point-by-point-Follow php development and provide professional web development tutorials
Script function add () {var name = document. getElementById ("name "). value; var url = document. getElementById ("url "). value; var list = document. getElementById ("list"); // dynamically create a node var link = document. createElement ("a"); link. setAttribute ("href", url); // sets the link property. innerHTML = name; // Add the delete button var button = document. createElement ("input"); button. setAttribute ("type", "button"); button. value = "delete";/** (1 ). event object indicates the object status Provides details about the object. IE browser is stored in the event attribute of the Window object. (2) The srcElement attribute is a reference to the Window object, Document object, or Element object that generates the event (3). The parentNode attribute returns the parent node of the specified node. (4) The removeChild () method deletes the subnode. **/Button. onclick = function (event) {var target; if (event = null) {target = window. event. srcElement;} else {target = event.tar get;} var div = target. parentNode; div. parentNode. removeChild (div); alert ("deleted successfully");} // Add the generated content var div = document. createElement ("div"); div. appendChild (button); div. insertBefore (link, button); list. appendChild (div);} script Site Name:URL:
The js instance running result is as follows:
The preceding js Code has been explained in detail. For details about attributes of DOM objects, refer to the manual.