当前位置:网站首页>Web APIs environment object - dark horse programmer
Web APIs environment object - dark horse programmer
2022-06-30 00:04:00 【Dark horse programmer official】
Notes updated in the early stage :Web API Basic cognition / obtain DOM Elements / Set up / modify DOM Element content and element attributes / Timer - Intermittent function / The basis of the event / Higher order function
One 、 Environment object
Environment objects refer to special objects inside functions Variable this , It represents the environment in which the current function runs
- Functions are called in different ways ,this The objects referred to are also different
- 【 Who is calling , this Who is the 】 Is a judgment this Rough rules for pointing to
- Call function directly , In fact, it's equivalent to window. function , therefore this Refer to window
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button> Click on </button>
<script>
// Environment object this He is an object
function fn() {
console.log(this)
}
// fn()
window.fn()
let btn = document.querySelector('button')
btn.addEventListener('click', function () {
console.log(typeof this)
// because btn Called this function , therefore this Point to btn
})
</script>
</body>
</html>Two 、 Programming idea
- Use for loop
- adopt this Or the subscript finds itself or the corresponding element
Exclusive thoughts :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.pink {
background: pink;
}
</style>
</head>
<body>
<button> The first 1 individual </button><button> The first 2 individual </button><button> The first 3 individual </button><button> The first 4 individual </button><button> The first 5 individual </button>
<script>
let btns = document.querySelectorAll('button')
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener('click', function () {
// this.classList.add('pink')
// Get rid of everyone
for (let j = 0; j < btns.length; j++) {
btns[j].classList.remove('pink')
}
// Resurrect myself
this.classList.add('pink')
})
}
</script>
</body>
</html>Exclusive thought upgrade :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.pink {
background: pink;
}
</style>
</head>
<body>
<button class="pink"> The first 1 individual </button><button> The first 2 individual </button><button> The first 3 individual </button><button> The first 4 individual </button><button> The first 5 individual </button>
<script>
let btns = document.querySelectorAll('button')
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener('click', function () {
// this.classList.add('pink')
// // Get rid of everyone
// for (let j = 0; j < btns.length; j++) {
// btns[j].classList.remove('pink')
// }
// I just need to find the one pink class , Delete
document.querySelector('.pink').classList.remove('pink')
// my
this.classList.add('pink')
})
}
</script>
</body>
</html>Dark horse front-end column has a lot of dry goods , Focus on relearning , It's convenient ~
2022 Front end learning roadmap : Course 、 Source code 、 note , Technology stack In addition, the circuit diagram is updated in real time ! Friends who need after-school materials , You can tell me directly .

边栏推荐
- 这个简单的小功能,半年为我们产研团队省下213个小时
- Sword finger offer 15 Number of 1 in binary
- Cloner un Graphe non recté [bfs accède à chaque bord et pas seulement aux noeuds]
- 云和恩墨盖国强,识别它、抓住它,在国产数据库沸腾以前
- How to view the CPU cores and threads in win11? Win11 view the tutorial of how many cores and threads the CPU is
- Web APIs 环境对象 丨黑马程序员
- Viewing splitchunks code segmentation from MPX resource construction optimization
- New titanium cloud service won the "2022 love analysis · panoramic report of it operation and maintenance manufacturers" cloud management platform CMP representative manufacturer
- LC: effective Sudoku + rotating image
- Bee common configuration
猜你喜欢
![克隆无向图[bfs访问每条边而不止节点]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
克隆无向图[bfs访问每条边而不止节点]
solo 博客皮肤导入 skins 文件夹后出现 500 错误

QT learning 05 introduction to QT creator project

QT learning 03 birth and essence of QT

Basic tutorial for installing monggodb in win10

云和恩墨盖国强,识别它、抓住它,在国产数据库沸腾以前

FPGA Development (2) -- IIC communication

QT learning 01 GUI program principle analysis

333333333333333333333333333333

How to view the CPU cores and threads in win11? Win11 view the tutorial of how many cores and threads the CPU is
随机推荐
Construction of module 5 of actual combat Battalion
Set up security groups, record domain names, and apply for SSL certificates
6.29 problem solving
小程序插件接入、开发与注意事项
Analysis of define incdir command in TCL script of Modelsim
After working in the software development industry for six years, I changed my ideas in those years
solo 博客皮肤导入 skins 文件夹后出现 500 错误
LC:有效的数独 + 旋转图像
New CorelDRAW technical suite2022 latest detailed function introduction
333333333333333333333333333333
Unity splashimage scaling problem
shell-位置参数变量和预定义变量
Common knowledge of ECS security settings
克隆無向圖[bfs訪問每條邊而不止節點]
克隆无向图[bfs访问每条边而不止节点]
Solr基础操作14
Siemens low code version 9.14: meet different needs
西门子低代码 9.14版本: 满足不同需求
我想知道今天还可以开户么?另外想问,现在在线开户安全么?
[LeetCode] 只出现一次的数字【136】