当前位置:网站首页>day31 js笔记 DOM下 2021.09.26
day31 js笔记 DOM下 2021.09.26
2022-06-28 11:20:00 【即将成为大佬的小梦】
Dom节点:
- 元素/标签节点:html标签下面的所有标签/元素
- 属性节点:标签内的属性
- 文本节点:标签内的所有文字内容
获取子节点及子元素节点:(获取子节点时 有标签的就输出标签 没有标签就输出#text)
- childNodes 获取标签下面的所有子节点
- children 获取标签下面的所有子元素节点
- firstChild 获取标签下面的第一个子节点
- lastChild 获取标签下面的最后一个子节点
- firstElementChild 获取标签下面的第一个子元素节点
- lastElementChild 获取标签下面的最后一个子元素节点

获取兄弟节点:
- previousSibling 获取到上一个兄弟节点
- previousElementSibling 获取到上一个兄弟元素节点
- nextSibling 获取到下一个兄弟节点
- nextElementSibling 获取到下一个兄弟元素节点
- parentNode 获取到父级节点
- parentElement 获取到父级元素节点
- attributes 获取元素的属性

节点的属性:
- nodeType 节点的类型
- nodeName 节点的名字
- nodeValue 节点的值

操作节点:
- 增加 document.createElement('创建的标签名字')
- 删除 父节点.removeChild(删除的子级节点)
- 修改 父节点.replaceChild(新的节点,被替换的节点)
- 插入 父节点.appendChild(子节点)

- 放在某一个节点的前面 父节点.insertBefore(新节点,旧节点)
- 复制节点 被复制的节点.cloneNode(参数)
- 参数写: true 不仅复制结构 还可以复制文本内容
- 参数不写:: 仅复制结构

获取行内样式: dom元素.style.属性 = '属性值'
获取非行内的样式: window.getComputedStyle(标签元素) - 兼容: dom元素.currentStyle.属性
获取元素的偏移量: 盒子元素距离浏览器的左上间距
- offsetLeft 左侧的偏移量
- offsetTOp 顶部的偏移量
注意:
- 盒子外侧距离浏览器的间距
- margin、定位 的大小会影响 (浮动会影响但是不会使用)
- 位移不会影响
![]()
获取元素自身大小:
- offsetWidth/offsetHeight 包含content、padding 包含border
- clientWidth/clientHeight 包含content、padding 不包含border

边栏推荐
- What is the function of ICMP Protocol and the principle of Ping of death attack?
- BigDecimal 类的 compareTo() 和 equals()方法
- 第2章 还记得点、线、面吗(二)
- Scientific research - web of science retrieval skills
- 时间戳和date转换「建议收藏」
- 合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
- [cloud resident co creation] detailed introduction to DWS alarm service DMS and cluster connection mode
- day34 js笔记 正则表达式 2021.09.29
- 关于Pytorch中双向LSTM的输出表示问题
- Gee: mcd64a1 based globfire daily fire data set
猜你喜欢

New listing of operation light 3.0 - a sincere work of self subversion across the times!

培训通知|2022年境外中资企业机构及人员疫情防控和安全防范专题培训通知

Dataease installation upgrade
![[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)](/img/e8/21d8d81a3d7b544687d6adc06ad4b1.png)
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)

Yann LeCun新论文:构建自动智能体之路

Debug debugging in katalon

2022中国信通院首届业务与应用安全发展论坛成功召开!

行业分析| 快对讲,楼宇对讲

Spatial-Temporal时间序列预测建模方法汇总

QML控件类型:TabBar
随机推荐
MySql5.7添加新用户
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
JS基础5
2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
将浏览器中的文件 url转换为File流
选择哪种编程语言,会吸引优秀的人才?
数据库系列:有什么办法对数据库的业务表进行无缝升级
基于验证码识别的机器学习项目captcha_trainer操作实践
100 important knowledge points that SQL must master: retrieving data
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
ThreadLocal的简单理解
Spatial-Temporal时间序列预测建模方法汇总
Machine learning project captcha based on verification code recognition_ Trainer operation practice
时间戳和date转换「建议收藏」
Jetpack Compose Desktop 桌面版本的打包和发布应用
Katalon framework tests web (XX) custom keywords and upload pop-up operations
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!
It is safer for individuals to choose which securities company to open an account for buying floor funds