getAttribute:获得元素的属性
setAttribute:设置元素的属性
1、getAttribute
getAttribute是一个函数,他只包含一个参数–你打算查询的参数的名字。
1 |
object.getAttribute(attribute); |
getAttribute不属于document对象,所以不能通过document对象调用,他只能通过元素节点对象调用。
可以与getElementsByTagName方法合用
1 |
var paras = documents.getElementsByTagName("p"); |
2、setAttribute
setAttribute 也只能用于节点元素对象调用。
1 |
var shopping = document.getElementById("purchases"); |
近期评论