亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

XML DOM setAttribute() 方法

定義和用法

setAttribute() 方法創(chuàng)建或改變某個新屬性。

語法:

elementNode.setAttribute(name,value)
參數(shù) 描述
name 必需。規(guī)定要設(shè)置的屬性名。
value 必需。規(guī)定要設(shè)置的屬性值。

說明

該方法把指定的屬性設(shè)置為指定的值。如果不存在具有指定名稱的屬性,該方法將創(chuàng)建一個新屬性。

實例

在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數(shù) loadXMLDoc()。

下面的代碼片段向 "books.xml" 中的所有 <book> 元素添加一個 "edition" 屬性:

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("book");

for(i=0;i<x.length;i++)
{
x.item(i).setAttribute("edition","first");
}

//Output book title and edition value
x=xmlDoc.getElementsByTagName("title");
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write(" - Edition: ");
document.write(x[i].parentNode.getAttribute('edition'));
document.write("<br />");
}

輸出:

Everyday Italian - Edition: FIRST
Harry Potter - Edition: FIRST
XQuery Kick Start - Edition: FIRST
Learning XML - Edition: FIRST