XML DOM removeNamedItem()เมธอด
❮ วัตถุ NamedNodeMap
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books.xml " ลงใน xmlDoc วนซ้ำผ่านองค์ประกอบ <book> และลบแอตทริบิวต์ของหมวดหมู่:
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var txt = "";
var x = xmlDoc.getElementsByTagName('book');
txt +=
x.item(0).attributes.length + "<br>";
x.item(0).attributes.removeNamedItem("category");
txt += x.item(0).attributes.length;
document.getElementById("demo").innerHTML = txt;
}
ความหมายและการใช้งาน
removeNamedItem() วิธีการลบโหนดที่ระบุ
หากแอตทริบิวต์ที่ลบออกมีค่าเริ่มต้น แอตทริบิวต์ใหม่จะปรากฏขึ้นทันทีพร้อมค่าเริ่มต้น รวมทั้ง URI เนมสเปซ ชื่อท้องถิ่น และคำนำหน้า หากมี
เมธอดนี้ส่งคืนโหนดที่ถูกลบ
ไวยากรณ์
removeNamedItem(nodename)
Parameter | Description |
---|---|
nodename | The name of the node to remove |
❮ วัตถุ NamedNodeMap