XML DOM removeAttributeNS() 方法

定義和用法

removeAttributeNS() 方法刪除由命名空間和名稱指定的屬性。

語法:

elementNode.removeAttributeNS(ns,name)
參數 描述
ns จำเป็นต้องกำหนดชื่อชั้นของคุณสมบัติที่ต้องการลบ
name จำเป็นต้องกำหนดชื่อของคุณสมบัติที่ต้องการลบ

ตัวอย่าง

ในทุกตัวอย่าง พวกเราจะใช้แบบ XML books_ns.xmlและฟังก์ชัน JavaScript loadXMLDoc()

บทความเขียนด้านล่างนี้จะลบคุณสมบัติ "lang" จากองค์ประกอบ <title> แรกในแบบ XML จาก "books_ns.xml":

xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.codew3c.com/children/";
document.write("Attribute Found: ");
document.write(x.hasAttributeNS(ns,"lang"));
x.removeAttributeNS(ns,"lang");
document.write("<br />Attribute Found: ");
document.write(x.hasAttributeNS(ns,"lang"));

ออกโดย:

Attribute Found: true
Attribute Found: false