& Lt; html & gt; & lt; head & gt; & lt;/head & gt; & lt; body & gt; & lt; formid & quot; myform & quot; & gt; & lt; inputtype & quot; text & quot; value & quot; get id & quot; getId & quot; & gt; & lt; in
Script // DOM object method // getElementById returns the element with the specified ID/* var byid = document. getElementById ("getId"); alert (byid. value); // get id // getElementsByTagName returns the list of nodes (Set/node array) containing all elements with the specified tag name var tagname = document. getElementsByTagName ("input"); alert (tagname [0]. value); // get id // createElement create Element Node var myform = document. getElementById ("myform"); var e = document. createElement ("input"); // create the input element e. type = "button"; // defines the input type value e. value = "haha"; // defines the value for the input value // appendChild () adds the new subnode to the specified node myform. appendChild (e); // Add the created input form to the form // insertBefore () Insert a new subnode document before the specified subnode. body. insertBefore (e, myform); // Add input to front of form // createAttribute () Create attribute node var att = document. createAttribute ("class"); att. value = "democlass"; // setAttributeNode () method to add a new property node document. getElementsByTagName ("input") [0]. setAttributeNode (att); // createElement creates an element node var newel = document. createElement ("p"); // The createTextNode () method creates a new text node newtext = document. createTextNode ('xixihahaha'); // appendChild () adds a new subnode to the specified node newel. appendChild (newtext); // appendChild () adds a new subnode to the specified node myform. appendChild (newel); // setAttribute () can be used to create a new property when the property does not exist. We can use this method to create a new property x = document. getElementsByTagName ("input"); x [0]. setAttribute ("asdasd", "first"); // replaceChild () method: Replace the node // The first parameter is the new node // The second parameter is the old node (the node to be replaced) var y1 = document. getElementsByTagName ("input") [1]; var y2 = document. getElementsByTagName ("input") [2]; myform. replaceChild (y2, y1); // removeChild () method to delete a specified node // when the node to be deleted is located, you can use the parentNode attribute and removeChild () method to delete this node var span1 = document. getElementsByTagName ("span") [0]; span1.parentNode. removeChild (span1); */script