当前位置:网站首页>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
边栏推荐
猜你喜欢

Node installation

Kettle实验

ATSS(CVPR2020)

小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab

Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem

Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread

MySQL小練習(僅適合初學者,非初學者勿進)

What is monitoring intelligent playback and how to use intelligent playback to query video recording

成功的DevOps Leader 应该清楚的3个挑战

Kettle实验 (三)
随机推荐
Simple understanding of arguments in JS
Data visualization: use Excel to make radar chart
LeetCode396. Rotate array
653. Sum of two IV - input BST
First principle mind map
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
ALV树(LL LR RL RR)插入删除
基于ThinkPHP5版本TRC20-资金归集解决方案
Secrets in buffctf file 1
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
Little girl walking
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
Vivo, hardware safe love and thunder
Kettle实验 (三)
Leetcode题库78. 子集(递归 c实现)
Flink SQL realizes the integration of stream and batch
LGB, XGB, cat, k-fold cross validation
Go language learning notes - structure | go language from scratch
Pre parsing of JS