XML DOM appendData() పద్ధతి
నిర్వచనం మరియు ఉపయోగం
appendData()
పద్ధతి కమెంట్ నోడ్ల చివరికి డాటా జోడించడానికి ఉపయోగించబడుతుంది.
సింతాక్స్
commentNode.appedData(string)
పారామీటర్లు | వివరణ |
---|---|
string | అనివార్యము. కమెంట్ నోడ్లకు జోడించవలసిన స్ట్రింగ్. |
ప్రతిమాత్రము
క్రింది కోడ్ "books_comment.xml" ను xmlDoc లోకి లోడ్ చేసి మొదటి కమెంట్ ఎలమెంట్లో టెక్స్ట్ జోడించడానికి ఉపయోగించబడుతుంది:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_comment.xml", true); xhttp.send(); function myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book")[0].childNodes; for (i = 0; i < x.length; i++) { // కమెంట్ నోడ్లను మాత్రమే ప్రాసెస్ చేయుము if (x[i].nodeType == 8) { x[i].appendData(" ప్రత్యేక ప్రస్తావన"); txt += x[i].data + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
在上面的例子中,我们用了循环和 if 测试语句,来确保我们只处理注释节点。注释节点的节点类型为 8。