< html xmlns="www.w3.org/1999/xhtml"> Willkommen bei DOM World! <br> var nodeStatus = function (node) {<br> var temp = "" ;<br> if (node.nodeName != null) {<br> temp += "nodeName:" + node.nodeName + "n";<br> }<br> else {<br> temp "Knotenname :null!n"; //<br>,n<br> }</p> <p>if (node.nodeType != null) {<br> temp += "nodeType:" + node.nodeType + "n";<br> }<br> else {<br> temp += "nodeType:null!n";<br> }</p> <p>if (node.nodeValue != null) {<br> temp += "nodeValue:" + node.nodeValue + "n";<br> }<br> else {<br> temp += "nodeValue:null!n";<br> }</p> <p>return temp;<br> }</p> <p>var currentElement = document.getElementById('p1');<br> var msg = nodeStatus(currentElement);<br> //alert(msg);<br> var firstChild = currentElement.firstChild;<br> msg += nodeStatus(firstChild);</p> <p>//父亲的下一个儿子->弟弟<br> var youngBrother = firstChild.nextSibling;<br> msg += nodeStatus(youngerBrother);</p> <p>//2弟的儿子=p父亲的大孙子<br> var grandSon = youngBrother.firstChild;<br> msg += nodeStatus(grandSon);</p> <p>//孙子的父亲<br> var grandSonParent = grandSon.parentNode;<br> msg += nodeStatus(grandSonParent);</p> <p>//孙子的父亲的兄长<br> var grandSonParentElderBrother = grandSonParent. previousSibling<br> msg = nodeStatus(grandSonParentElderBrother) ;</p> <p>//大哥的父亲<br> var parent = grandSonParentElderBrother.parentNode;<br> msg += nodeStatus(parent);</p> <p>//父亲的小儿子<br> var lastChild = parent.lastChild;<br> msg += nodeStatus(lastChild);</p> <p>//父亲的所有儿子<br> var allChildInfo = "";<br> var allChild = parent.childNodes;<br> für (var i = 0; ich < allChild.length; i++) {<br/> allChildInfo += nodeStatus(allChild[i]);<br/> }</p><p>//alert(msg);<br/> Beans Käse Milch<br> var oPurchases = document.getElementById( 'purchases');<br> var items = document.getElementsByTagName("li");</p> <p>var info = typeof (oPurchases) + '<br>';<br> for (var i = 0 ; i < items.length; i++) {<br> info += typeof (items[i]) + "<br>";<br> }</p> <p>//document.write(info) ;<br> <br> var rdItems = document.getElementsByName("rdGroup");<br> var rdInfo = "";<br> for (var i = 0; ich < rdItems.length; i++) {<br/> rdInfo += nodeStatus(rdItems[i]) + 'n';<br/> }</p><p>//alert(rdInfo);</p><p><br/> </ script></p> <p><p title="pTitle" style="color:Blue;font-size:30px;" <br/> id="pSample"><br> Dies ist das erste Beispiel!</p><br> <script type="text/javascript"><br> var oSample = document.getElementById(' pSample');<br> var attr = "";<br> //取得所有属性内容<br> attr += "原标题是:"<br> + oSample.getAttribute( „Titel“) + ‚n‘ ;<br> attr += "样式是:"<br> + "color="<br> + oSample.getAttribute("style").color<br> + ",fontSize="<br> + oSample.getAttribute ("style").fontSize + 'n';</p> <p>//alert(attr);</p> <p>//改变属性内容,新增一个名字的属性<br> oSample.setAttribute( "title", "newTitle");<br> oSample.setAttribute("name", "pName");</p> <p>attr += "新标题是:"<br> + oSample.getAttribute("title ") + 'n'<br> + "新名字是:" + oSample.getAttribute("name");</p> <p>//alert(attr);</p> <p>//删除属性<br> oSample.removeAttribute("name");</p> <p>attr += "n现在的名字是:"<br> + oSample.getAttribute("name");</p> <p>//alert (attr);</p> <p><br> var createElement = function () {<br> var eleInfo = "";</p> <p>//段落<br> var newParagraph =<br> document.createElement ('p');</p> <p>eleInfo += nodeStatus(newParagraph) + 'n';</p> <p>//文本内容(儿子)<br> var newTextNode =<br> document.createTextNode( '我是段落里面的文字');</p> <p>eleInfo += nodeStatus(newTextNode) + 'n';</p> <p>newParagraph.appendChild(newTextNode);</p> <p>//第一个儿子<br> eleInfo += nodeStatus(newParagraph.firstChild) + 'n';</p> <p>document.body.appendChild(newParagraph);</p> <p>//return eleInfo;<br> } </p> <p>//alert(createElement());</p> <p>//Ein neues Element einfügen<br> var doInsertBefore = function (o) {<br> var myDiv = document.getElementById('myDiv'); //Das Div-Element abrufen<br> var newInput = document.createElement ( 'input'); //Neues Eingabeelement<br> ; //Ein neues Textfeld vor der Schaltfläche einfügen<br> }<br><br>var doRemoveChild = function (o) {</p> var myDiv = o.parentNode; //übergeordnetes Element Holen Sie sich den übergeordneten Knoten des aktuellen Objekts<p> var firstChild = myDiv.firstChild; //Der erste untergeordnete Knoten des übergeordneten Knotens<br> } <br> < ! --Ein neues DOM-Element wird eingefügt--> "doRemoveChild(this)"/> div>