当前位置:网站首页>Exclusive thoughts and cases of JS
Exclusive thoughts and cases of JS
2022-04-23 09:27:00 【Small white egg tart】

Case a : Five buttons , Click whose background color turns pink
var btns = document.getElementsByTagName('button');
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function() {
// First remove all the background colors
for (var i = 0; i < btns.length; i++) {
btns[i].style.backgroundColor = '';
}
// Then change the color of the current element button
this.style.backgroundColor = 'pink';
}
}
Case 2 Baidu skin changing effect
var imgs = document.querySelector('.baidu').querySelectorAll('img');
// Loop register events
for (var i = 0; i < imgs.length; i++) {
imgs[i].onclick = function() {
// Click the path of the picture to body
// console.log(this.src);
document.body.style.backgroundImage = 'url(' + this.src + ')'
}
}
The table of case 3 has been changed

// get
var trs = document.querySelector('tbody').querySelectorAll('tr');
for (var i = 0; i < trs.length; i++) {
// Mouse over
trs[i].onmouseover = function() {
this.className = 'bg';
}
// Mouse off recovery onmouseout
trs[i].onmouseout = function() {
this.className = '';
}
}
Case four : Select all form deselect all

//1. Select all and cancel all
// Get elements
var j_cbAll = document.getElementById('j_cbAll');
var j_tbs = document.getElementById('j_tb').getElementsByTagName('input');
// The binding event
j_cbAll.onclick = function() {
// You can get the selected status of the current check box
// console.log(this.checked);
for (var i = 0; i < j_tbs.length; i++) {
j_tbs[i].checked = this.checked;
// Here there is no ++‘’ Because this.checked Identified as a keyword
}
}
//2. The check button affects the above
for (var i = 0; i < j_tbs.length; i++) {
j_tbs[i].onclick = function() {
// Controls whether the select all button is selected
var flag = true;
// console.log(this.checked);
for (var i = 0; i < j_tbs.length; i++) {
if (!j_tbs[i].checked) {
flag = false;
// As long as one is not selected, there is no need to judge the rest
break;
}
}
j_cbAll.checked = flag;
}
}
版权声明
本文为[Small white egg tart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624114102.html
边栏推荐
- Using JS to realize a thousandth bit
- Buuctf [actf2020 freshman competition] include1
- Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
- [in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
- NPM installation yarn
- RSA 加密解密签名验签
- Go language learning notes - slice, map | go language from scratch
- Write down the post order traversal of the ~ binary tree
- A must see wechat applet development guide 1 - basic knowledge
- How to read excel table to database
猜你喜欢

nn. Explanation of module class

Go language learning notes - exception handling | go language from scratch

搞不懂时间、时间戳、时区,快来看这篇
![[C language] document operation](/img/89/b19dda13d27e37fedf6736c102245b.png)
[C language] document operation

错题汇总1

GoLand debug go use - white record

AQS & reentrantlock implementation principle

Matlab draw five-star red flag

Flink SQL realizes the integration of stream and batch

Project upload part
随机推荐
MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
First principle mind map
SAP 101K 411k inventory change
About CIN, scanf and getline, getchar, CIN Mixed use of getline
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
[C language] document operation
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
How to protect open source projects from supply chain attacks - Security Design (1)
Little girl walking
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
How does kubernetes use harbor to pull private images
3、 6 [Verilog HDL] gate level modeling of basic knowledge
Secrets in buffctf file 1
Go language learning notes - language interface | go language from scratch
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
基于ThinkPHP5版本TRC20-资金归集解决方案
Applet error: cannot read property'currenttarget'of undefined
Simple understanding of arguments in JS
Project upload part
Matlab draw five-star red flag