javascript中dom常用方法有哪些?
时间:2022-02-11 16:04
javascript中dom常用方法有:1、getElementById;2、getElementsByClassName;3、getElementsByTagName;4、getAttribute;5、setAttribute。 本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。 一、 1、getElementById 2、getElementsByClassName 3、getElementsByTagName 4、getAttribute 5、setAttribute 二、 其中可以从document对象调用获取元素节点有以下三种方法 1、getElementById document.getElementById(id) 根据ID,将返回一个与那个有着同样id属性的元素节点对应的对象 2、getElementsByClassName document.getElementsByClassName(class)根据类名,将返回一个对象数组,对应着文档里一组特定的元素节点 3、getElementsByTagName element.getElementsByTagName(Tag) 根据标签名,将返回一个对象数组,对应着文档里一组特定的元素节点 其次是不能从document对象中调用,只能通过元素节点对象调用的两种方法 1、getAttribute object.getAttribute(attribute) 只用一个参数,打算查询,获取的属性的名字 2、setAttribute object.setAttribute(attribute,value),可以对属性节点的值做出修改 【推荐学习:javascript高级教程】 以上就是javascript中dom常用方法有哪些?的详细内容,更多请关注gxlsystem.com其它相关文章!