XML DOM removeAttribute()เมธอด
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " 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 xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("book");
document.getElementById("demo").innerHTML =
x[0].getAttribute('category')
+ "<br>";
x[0].removeAttribute('category');
document.getElementById("demo").innerHTML +=
x[0].getAttribute('category');
}
เอาท์พุท:
cooking
null
ความหมายและการใช้งาน
removeAttribute() วิธีการลบแอตทริบิวต์ที่ระบุ
หากมีการกำหนดค่าเริ่มต้นสำหรับแอตทริบิวต์ใน DTD แอตทริบิวต์ใหม่จะปรากฏขึ้นพร้อมค่าเริ่มต้น
ไวยากรณ์
elementNode.removeAttribute(name)
Parameter | Description |
---|---|
name | Required. Specifies the attribute to remove |
❮ วัตถุธาตุ