当前位置:网站首页>DOM文档
DOM文档
2022-06-26 05:27:00 【程序员的朴实无华】
1.DOM是文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口。在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象的标准模型就称为DOM。
DOM又称为文档树模型

文档:一个网页可以称为文档
节点:网页中所有的内容都是节点
元素:网页中的标签
属性:标签的属性
2.模拟文档树结构

3.DOM经常进行的操作
获取元素
动态创建元素
对元素进行操作
事件
4.为什么要获取页面元素
列如:我们想要操作页面上的某一部分,需要先获取到该部分对应的元素,才进行操作
根据id获取元素
根据标签名获取元素
根据name获取元素
根据类名获取元素
根据选择器获取元素
5.总结
getElementById()
getElementsByTagName()
getElementsByName()
getElementsByClassName()
querySelector()
querySelectorAll()
6.事件
事件:触发-响应机制
Event接口表示在DOM中发生的任何事件,一些是用户生成的(例如鼠标或键盘事件),而其他由API生成。
事件三要素:
事件源:触发事件的元素
事件类型:事件的触发方式
事件处理程序:事件触发后要执行的代码
7.属性操作
非表单元素的属性
Href、title、id、src、ClassName
表单元素属性
value 用于大部分表单元素的内容获取(option除外)
type 可以获取input标签的类型(输入框或复选框等)
disabled 禁用属性
checked 复选框选中属性
selected 下拉菜单选中属性
getAttribute() 获取标签行内属性
setAttribute() 设置标签行内属性
removeAttribute() 移除标签行内属性
与element.属性的区别: 上述三个方法用于获取任意的行内属性。
8.创建元素的三种方式
Document.write()
InnerHTML
Document.createElement()
9.事件对象的属性和方法
event.type 获取事件类型
clientX/clientY 所有浏览器都支持,窗口位置
pageX/pageY IE8以前不支持,页面位置
event.target || event.srcElement 用于获取触发事件的元素
event.preventDefault() 取消默认行为
10.常用的鼠标和键盘事件
onmouseup 鼠标按键放开时触发
onmousedown 鼠标按键按下触发
onmousemove 鼠标移动触发
onkeyup 键盘按键按下触发
onkeydown 键盘按键抬起触发
边栏推荐
- Anaconda creates tensorflow environment
- Redis discovery bloom filter
- Create SSH key pair configuration steps
- Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports
- Classic theory: detailed explanation of three handshakes and four waves of TCP protocol
- Fedora alicloud source
- 第九章 设置结构化日志记录(一)
- Baidu API map is not displayed in the middle, but in the upper left corner. What's the matter? Resolved!
- Owasp-top10 in 2021
- Two step processing of string regular matching to get JSON list
猜你喜欢

cartographer_optimization_problem_2d

Fedora alicloud source

The localstorage browser stores locally to limit the number of forms submitted when tourists do not log in.

How to rewrite a pseudo static URL created by zenpart

Official image acceleration

Leetcode114. 二叉树展开为链表

redis探索之布隆过滤器

uniCloud云开发获取小程序用户openid

apktool 工具使用文档

Serious hazard warning! Log4j execution vulnerability is exposed!
随机推荐
C# 39. Conversion between string type and byte[] type (actual measurement)
Positioning setting horizontal and vertical center (multiple methods)
The State Council issued a document to improve the application of identity authentication and electronic seals, and strengthen the construction of Digital Government
FastAdmin Apache下设置伪静态
RESNET in tensorflow_ Train actual combat
Keras actual combat cifar10 in tensorflow
Secondary bootloader about boot28 Precautions for ASM application, 28035
How does P2P technology reduce the bandwidth of live video by 75%?
Uni app ceiling fixed style
LeetCode_ Binary search tree_ Simple_ 108. convert an ordered array to a binary search tree
Protocol selection of mobile IM system: UDP or TCP?
第九章 设置结构化日志记录(一)
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
As promised: Mars, the mobile terminal IM network layer cross platform component library used by wechat, has been officially open source
cartographer_optimization_problem_2d
app 应用安装到手机,不显示图标,引发的思考
【ARM】在NUC977上搭建基于boa的嵌入式web服务器
Internship May 29, 2019
[activity recommendation] cloud native, industrial Internet, low code, Web3, metauniverse... Which is the architecture hot spot in 2022
Ad tutorial series | 4 - creating an integration library file