当前位置:网站首页>BOM and DOM operations
BOM and DOM operations
2022-06-26 19:19:00 【EijiLei】
List of articles
BOM And DOM operation
BOM Browser object model >>>: Use js Operating the browser
DOM Document object model >>>: Use js Operation front page
1.BOM operation
window.open() Open a new window
window.close() Close the current window
history.forward() One page ahead
history.back() One page back
location.href() obtain URL
location.href='URL' Jump to blade assignment page
location.reload() Reload page
2.DOM Find label for operation
` Prefix keyword document`
Basic search ( The core )
document.getElementById according to ID Get a tag
document.getElementsByClassName according to class Property acquisition
document.getElementsByTagName Get the tag collection according to the tag name
` If our js The code needs a tag on the page to be loaded Then the js The code should be written in body The lowest part of the interior or leading into the outside js file `
Indirect search
parentElement Parent node label element
children All sub tags
firstElementChild The first child tag element
lastElementChild The last child tag element
nextElementSibling Next brother tag element
previousElementSibling Last brother tag element
3. Node operation
var aEle = document.createElement('a'); # Create a label
aEle.setAttribute('href','https://www.mmzztt.com/')
# Set properties
aEle.innerText = ' It's not good ?' # Set content text
document.getElementsByTagName('p')[0].appendChild(aEle)
# Dynamic addition
""" Make sure you know what you're dealing with """
imgEle.getAttribute('title') # Get tag attributes
innerText
Without the assignment symbol is to get the internal text
The assignment symbol is used to set the built-in text
Unrecognizable HTML label
innerHTML
Without the assignment symbol is to get the internal label + Text
Adding the assignment symbol is to set the built-in label + Text
4. Get value operation
Ordinary text data acquisition
Label object .value
Special file data acquisition
Label object .value Just get a file address
Label object .files[0] Get single file data
Get objects .files Get all file data
5.class operation
classList See all the classes
classLIst.remove(cls) Delete specified class
classLIst.add(cls) Add the class
classLIst.contains(cls) There is returned true, Otherwise return to false
classLIst.toggle(cls) Delete if it exists , Otherwise, add
6. Style operation
Label object .style. Property name = Property value
7. event
Just give HTML Element add custom function
How to bind Events 1
<button onclick="func()"> Am I </button>
<script>
function func() {
alert(123)
}
</script>
How to bind Events 2
<button id="d1"> Choose me </button>
<script>
// 1. Find labels first
var btnEle = document.getElementById('d1')
// 2. The binding event
btnEle.onclick = function () {
alert(456)
}
</script>
8. Built in parameters this
this It refers to the currently operated object itself
Use... Inside the function body code of the event
btnEle.onclick = function () {
alert(456)
console.log(this)
}
边栏推荐
- 8VC Venture Cup 2017 - Final Round C. Nikita and stack
- Feign远程调用
- To: Apple CEO Cook: great ideas come from constantly rejecting the status quo
- Kubernetes resource topology aware scheduling optimization
- Numpy's Matplotlib
- JS mobile terminal touch screen event
- Feign remote call
- 抖音实战~首页视频~下拉刷新
- 微信小程序 uniapp 左滑 删除 带删除icon
- Pinda general permission system (day 1~day 2)
猜你喜欢

Image binarization

Redis single sign on system + voting system

微信小程序 自定义 弹框组件

Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees

SSO微服务工程中用户行为日志的记录

Tiktok practice ~ sharing module ~ copy short video link

Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems

ARM裸板调试之串口打印及栈初步分析

9. Intelligent transportation project (2)

Tree array
随机推荐
Take you to resolve hash conflicts and implement a simple hash table,
刷新三观的HP-UX系统中的强指针赋值出core问题
Logstash安装及使用
读书笔记:《过程咨询 III》
几种常见的UML关系图汇总
Using cache in vuex to solve the problem of data loss in refreshing state
最小生成树、最短路径、拓扑排序、关键路径
【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
Pinda general permission system (day 1~day 2)
深度学习之Numpy篇
Preliminary analysis of serial port printing and stack for arm bare board debugging
Leetcode 238 product of arrays other than itself
知識點總結
Numpy之matplotlib
数据库SQL语句撰写
To: Apple CEO Cook: great ideas come from constantly rejecting the status quo
ROS query topic specific content common instructions
物联网协议的王者:MQTT
WebView load pdf
On the escape of inequality value