javascript中document的方法
时间: 2023-04-30 18:03:19 浏览: 77
JavaScript 中的 document 对象具有许多方法,其中一些常用的方法如下:
- getElementById(id):通过元素的 id 获取元素。
- getElementsByTagName(tagName):通过元素的 tagName 获取元素集合。
- getElementsByClassName(className):通过元素的 class 获取元素集合。
- querySelector(selector):通过 css 选择器获取第一个符合条件的元素。
- querySelectorAll(selector):通过 css 选择器获取所有符合条件的元素集合。
- createElement(tagName):创建一个新的元素。
- createTextNode(text):创建一个新的文本节点。
- appendChild(node):向一个元素中添加一个子节点。
- removeChild(node):从一个元素中删除一个子节点。
- replaceChild(newNode, oldNode):用新节点替换旧节点。
- addEventListener(event, function):为元素添加事件监听。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)