当前位置:网站首页>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
边栏推荐
- #yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
- Go language learning notes - structure | go language from scratch
- Set the maximum width of the body, but why does the background color of the body cover the whole page?
- Two ways for flutter providers to share data
- Kettle experiment (III)
- 小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
- How does kubernetes use harbor to pull private images
- Sql1 [geek challenge 2019]
- Your guide to lowering your cholesterol with TLC (continuously updated)
- 108. 将有序数组转换为二叉搜索树
猜你喜欢
随机推荐
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
OpenCV中的图像处理 —— 轮廓入门+轮廓特征
Canary publishing using ingress
MySQL of database -- overview and installation
Kettle实验
Notes on xctf questions
Two ways for flutter providers to share data
Common errors of VMware building es8
Flink SQL realizes the integration of stream and batch
npm ERR! network
Kettle实验 (三)
Kettle experiment
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
MySQL of database -- basic common query commands
[SQL Server fast track] view and cursor of database
ATSS(CVPR2020)
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
GoLand debug go use - white record
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
基于ThinkPHP5版本TRC20-资金归集解决方案






![Sql1 [geek challenge 2019]](/img/ad/afca09bc1da003393319af700e90e3.png)


