当前位置:网站首页>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
边栏推荐
- [Luke V0] verification environment 2 - Verification Environment components
- Summary of wrong questions 1
- 成功的DevOps Leader 应该清楚的3个挑战
- Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
- [in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
- Kettle实验
- Wechat applet catchtap = "todetail" event problem
- Kettle experiment (III)
- GoLand debug go use - white record
- Kettle实验 (三)
猜你喜欢

Go language learning notes - structure | go language from scratch

《信息系统项目管理师总结》第八章 项目干系人管理

ATSS(CVPR2020)

112. Path sum

三、6【Verilog HDL】基础知识之门级建模

Chapter VIII project stakeholder management of information system project manager summary

Harbor enterprise image management system

Node installation

Go language learning notes - array | go language from scratch

AQS & reentrantlock implementation principle
随机推荐
小女孩行走
LeetCode396. Rotate array
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
How to protect open source projects from supply chain attacks - Security Design (1)
112. 路径总和
Set the maximum width of the body, but why does the background color of the body cover the whole page?
MySQL小練習(僅適合初學者,非初學者勿進)
Two ways for flutter providers to share data
SAP 101K 411K 库存变化
JS case to find the maximum value, reverse the array, bubble sort
SQL used query statements
[SQL Server fast track] view and cursor of database
Failed to download esp32 program, prompting timeout
LeetCode 1611. The minimum number of operations to make an integer 0
About CIN, scanf and getline, getchar, CIN Mixed use of getline
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
2D 01 Backpack
NLLLoss+log_ SoftMax=CE_ Loss
Summary of common concepts and problems of linear algebra in postgraduate entrance examination
Leetcode-199 - right view of binary tree