当前位置:网站首页>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

边栏推荐
- MySQL installation configuration and solving the problem of forgetting root password when reinstalling MySQL
- Summary of spatial temporal time series prediction modeling methods
- vsftpd服务的部署及优化
- 毕业季 新的开始
- day34 js笔记 正则表达式 2021.09.29
- JS foundation 1-js introduction and operator
- 使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
- Jetpack Compose Desktop 桌面版本的打包和发布应用
- SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
- Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
猜你喜欢

Katalon framework tests web (XX) custom keywords and upload pop-up operations

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

数据库系列:有什么办法对数据库的业务表进行无缝升级

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
![[monkey] Introduction to monkey test](/img/70/5a7152d0b6b77df7f9d6ad0e09e000.png)
[monkey] Introduction to monkey test

JS基础1-JS引入与运算符

Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph

一套十万级TPS的IM综合消息系统的架构实践与思考

静态库的制作和使用

行业分析| 快对讲,楼宇对讲
随机推荐
乌国家安全与国防委员会秘书:将对俄境内目标进行精确打击
Makefile introduction
随机森林以及 AMR 训练出的诗词制造器
时间戳和date转换「建议收藏」
合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
Lihongyi, machine learning 7 Conclusion
Graduation season, some suggestions for you who are new to the society
mysql-. SQL file phishing Online
使用API快捷创建ECS
基于验证码识别的机器学习项目captcha_trainer操作实践
2022 开源软件安全状况报告:超41%的企业对开源安全没有足够的信心
Oracle 日期格式化异常:无效数字
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
2022中国信通院首届业务与应用安全发展论坛成功召开!
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
[function suggestion] select a space when multiple workspaces are started
《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!
培训通知|2022年境外中资企业机构及人员疫情防控和安全防范专题培训通知
合约量化交易系统开发 | 合约量化APP开发(现成案例)
使用 Calendar 计算时间