使用 getAttributeNode 和 setAttributeNode 的区别

difference between using getAttributeNode and setAttributeNode

我想知道使用getAttributeNode和setAttributeNode的区别:

var x = document.getElementsByTagName("IMG")[0];
x.getAttributeNode("src").value = "pic_bulbon.gif";
x.setAttributeNode("src").value = "pic_bulbon.gif";

Element.getAttributeNode() returns指定元素的指定属性,作为一个Attr节点。

Element.setAttribute() 用于添加新属性或更改指定元素上现有属性的值。

var x = document.getElementsByTagName("IMG")[0]; // Get the first image element
console.log(x.getAttributeNode("src")); // Returns the src value of image
x.setAttributeNode("src", "pic_bulbon.gif"); // Set src value of image