js-获取元素和属性的注意事项

JS里获取元素的方法有三种:getElementById() getElementsByTagName getElementsByClass()

1.getElementById(id)

圆括号里包含的函数参数加英文双引号"" ;

2.getElementsByTagName(tag)

返回的是数组

3.getElementsByClassName(class)

返回的是数组

JS里获取属性的方法 getAttribute(attribute)

getAttribute(attribute)属性不属于document对象,所以不能通过document对象调用,只能通过元素对象调用。

设置属性 object.setAttribute(attribute,value)

 

posted @ 2015-11-11 13:52  Annguowenhua2015  阅读(158)  评论(0编辑  收藏  举报