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

边栏推荐
- About mongodb error: connecting to: mongodb://127.0.0.1:27017/?compressors=disabled &gssapiServiceName=mongodb
- 一步步教你在Edge浏览器上安装网风笔记
- QPainter的使用入门:绘制象棋界面
- gyctf_2020_document
- 代码分析平台 SonarQube 实战
- Andorid source build/envsetup.sh 该知道的细节
- FPGA Development (2) -- IIC communication
- After working in the software development industry for six years, I changed my ideas in those years
- Official website of Greentree
- Solr基础操作13
猜你喜欢

6.29 problem solving

Cartoon security HIDS, EDR, NDR, XDR

Common knowledge of ECS security settings

QPainter的使用入门:绘制象棋界面

Yunhe enmo Guoqiang, identifiez - le, saisissez - le, avant l'ébullition de la base de données nationale

项目一:部署 LAMP ecshop电商平台

Halcon practical: design idea of solder joint detection

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

Jetpack之Room的使用,结合Flow

开始“收割”!钉钉调整“钉钉Teambition”免费用人数上限,超十人将无法正常用
随机推荐
500 error occurred after importing skins folder into solo blog skin
Halcon practical: design idea of solder joint detection
请指教什么是在线开户?另外,手机开户安全么?
Exploration and Practice on the future direction of byte cloud database
Golang6 reflection
How to write controller layer code gracefully?
爬虫入门实战:斗鱼弹幕数据抓取,附送11节入门笔记
这个简单的小功能,半年为我们产研团队省下213个小时
HTAP x cloud native: tidb accelerates the release of data value and realizes data agility
Zhongang Mining: Fluorite helps the construction and development of lithium battery in fluorine industry
打造一个 API 快速开发平台,牛逼!
modelsim的TCL脚本的define incdir命令解析
Analysis of define incdir command in TCL script of Modelsim
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
QT learning 01 GUI program principle analysis
Golang泛型的巧妙应用,防止变量空指针错误,防止结构体字段空指针错误
Sword finger offer 14- ii Cutting rope II
This simple little function saves 213 hours for our production research team in half a year
QPainter的使用入门:绘制象棋界面
Inspiration collection · evaluation of creative writing software: flomo, obsidian memo, napkin, flowus