XML DOM createComment() روش
تعریف و استفاده
createComment()
این روش نقاط نظر ایجاد میکند.
این روش Comment Object را برمیگرداند.
قوانین
createComment(data)
پارامتر | شرح |
---|---|
data | زیر نویسی، دادههای نقطه را مشخص میکند. |
مثال
کد زیر "books.xml" را به xmlDoc بارگذاری کرده و نقاط نظر را به عنصر <book> اضافه میکند:
مقادیر var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { اگر (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); توابع myFunction(xml) { مقادیر var x, i, newComment, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); برای (i = 0; i < x.length; i++) { newComment = xmlDoc.createComment("Revised April 2008"); x[i].appendChild(newComment); } برای (i = 0; i < x.length; i++) { txt += x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + " - " + x[i].lastChild.nodeValue + "<br>"; } document.getElementById("demo").innerHTML = txt; }