js修改标签属性值

获取和设置属性
getAttribute
object.getAttribute(attribute)
注:getAttribute方法不属于document对象,它只能通过元素节点对象调用。

setAttribute
object.setAttribute(attribute,value)

例子:
var shopping = document.getElementById("purchases");
shopping.setAttribute("title","a list of goods");


参考文章引自脚本之家:http://www.jb51.net/article/47040.htm

还有一种W3cschool,如图:



另一种还是W3cschool的:



扫描二维码关注公众号,回复: 15975910 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_40829962/article/details/78699027