当前位置:网站首页>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
边栏推荐
- Thread scheduling (priority)
- Simple understanding of arguments in JS
- Colorui solves the problem of blocking content in bottom navigation
- How to render web pages
- Distributed message oriented middleware framework selection - Digital Architecture Design (7)
- nn. Explanation of module class
- Brush classic topics
- Your guide to lowering your cholesterol with TLC (continuously updated)
- 成功的DevOps Leader 应该清楚的3个挑战
- [indexof] [lastIndexOf] [split] [substring] usage details
猜你喜欢
SAP 101K 411k inventory change
The most concerned occupations after 00: civil servants ranked second. What was the first?
Go language learning notes - array | go language from scratch
Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
Failed to download esp32 program, prompting timeout
[SQL Server fast track] view and cursor of database
Cross domain configuration error: when allowcredentials is true, allowedorigins cannot contain the special value "*“
Kettle实验 (三)
Matlab draw five-star red flag
Number of islands
随机推荐
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
I don't understand time, timestamp and time zone. Look at this article
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
基于ThinkPHP5版本TRC20-资金归集解决方案
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
员工试用期转正申请书(泸州老窖)
Brush classic topics
Four pictures to understand some basic usage of Matplotlib
Single sign on SSO
Summary of wrong questions 1
Open services in the bottom bar of idea
Common errors of VMware building es8
DVWA range practice
To remember the composition ~ the pre order traversal of binary tree
Kettle实验 (三)
2D 01 Backpack
Thread scheduling (priority)
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
Codeforces Round #784 (Div. 4)
Simple understanding of arguments in JS