XML DOM getAttributeNodeNS() ລະບົບ

ການອະທິບາຍ ແລະ ການນໍາໃຊ້

getAttributeNS() ຂະບວນການທີ່ຈະນຳໄປຮັບຂໍ້ມູນຕາມພາສານຳມະຕິ ແລະ ຊື່

ຂອງພາສາ

elementNode.getAttributeNodeNS(ns,name)
ປະເພາະ ອະທິບາຍ
ns ສຳຄັນ
name ສຳຄັນ

ຕົວຢ່າງ

ລະບຸກອອກຄວາມ: "books_ns.xml" ບັນທະຍາຍໃນ xmlDoc ແລະຈາກ <title> ສະມາຊິກທໍາອິດບັນທຶກ "lang" ອີງວິທະຍານ:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0];
    var ns = "https://www.codew3c.com/meishi/";
    var y = x.getAttributeNodeNS(ns,"lang");
    document.getElementById("demo").innerHTML =
    y.nodeName + " = " + y.nodeValue;
}

亲自试一试