วิธี removeAttributeNS() ของ XML DOM
คำนิยามและการใช้งาน
removeAttributeNS()
วิธีลบคุณสมบัติที่กำหนดโดยชื่อและชื่อช่วยขององค์ประกอบ
ภาษา
elementNode.removeAttributeNS(ns,name)
ตัวแปร | คำอธิบาย |
---|---|
ns | ความจำเป็น กำหนดชื่อช่วยของคุณสมบัติที่ต้องการลบ |
name | ความจำเป็น กำหนดชื่อของคุณสมบัติที่ต้องการลบ |
ตัวอย่าง
แบบรหัสใต้นี้จะลงทะเบียน "books_ns.xml" ใส่ xmlDoc และลบคุณสมบัติ "lang" จากองค์ประกอบ <title> แรก:
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/"; document.getElementById("demo").innerHTML = "Attribute Found: " + x.hasAttributeNS(ns, "lang"); x.removeAttributeNS(ns, "lang"); document.getElementById("demo").innerHTML += "<br>屬性找到: " + x.hasAttributeNS(ns, "lang"); }