请知悉:本文最近一次更新为 9年 前,文中内容可能已经过时。

setAttribute() 方法创建或改变某个新属性。
语法:
elementNode.setAttribute(name,value)
代码示例:

document.getElementsByTagName("a")[0].setAttribute("edition","first");

整理自:https://www.w3school.com.cn/xmldom/met_element_setattribute.asp

getAttribute() 方法返回指定属性名的属性值。
语法:
element.getAttribute(attributename);
代码示例:

document.getElementsByTagName("a")[0].getAttribute("target");

整理自:https://www.w3school.com.cn/jsref/met_element_getattribute.asp


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《JavaScript中setAttribute和getAttribute的用法-类似jQuery中的attr方法》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌