XML DOM getAttribute() روش

تعریف و استفاده

getAttribute() این روش با نام به ارزش ویژگی دسترسی دارد.

قوانین

elementNode.getAttribute(name)
پارامترها توضیح
name ضروری. مشخص می‌کند که از چه ویژگی‌ای برای دریافت ارزش استفاده شود.

مثال

معلومات زیر کد را برای بارگذاری "books.xml" به xmlDoc و دریافت ارزش ویژگی "category" همه عناصر <book> اجرا می‌کند:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var x, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    برای (i = 0; i < x.length; i++) {
        txt += x[i].getAttribute('category') + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

سماجی طور پر کوشاں