亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

HTML DOM createAttribute() 方法

HTML DOM Document對象

createAttribute()方法創(chuàng)建一個新的屬性節(jié)點,并將該屬性作為Attr對象返回。

DOM 并不強制以createAttribute()這種方式向特定元素添加何種類型的屬性。

使用attribute.value屬性設置屬性的值。

使用element .setAttributeNode()方法將新創(chuàng)建的屬性添加到元素。

或者,您可以使用element .setAttribute()方法代替createAttribute()方法。

語法:

document.createAttribute(name)
var node = document.getElementById("result");
var a = document.createAttribute("href");
a.value = "/";
node.setAttributeNode(a);
測試看看?/?

瀏覽器兼容性

所有瀏覽器完全支持createAttribute()方法:

Method
createAttribute()

參數(shù)值

參數(shù)描述
name包含屬性名稱的字符串

技術細節(jié)

返回值:表示創(chuàng)建的屬性的Attr對象
DOM版本:DOM級別1

更多實例

創(chuàng)建一個src屬性,其值為“clouds.png”,并將其插入到<img>元素中:

var node = document.querySelector("img");
var a = document.createAttribute("src");
a.value = "/run/images/clouds.png";
node.setAttributeNode(a);
測試看看?/?

HTML DOM Document對象