当前位置:网站首页>DOM系列之排他思想
DOM系列之排他思想
2022-07-19 07:34:00 【老__L】
1、什么是排他思想
如果有同一组元素,我们想要某一个元素实现某种样式, 需要用到循环的排他思想算法
- 所有元素全部清除样式(干掉其他人)
- 给当前元素设置样式 (留下我自己)
- 注意顺序不能颠倒,首先干掉其他人,再设置自己
2、示例
<button>按钮1</button>
<button>按钮2</button>
<button>按钮3</button>
<button>按钮4</button>
<button>按钮5</button>
<script> // 1. 获取所有按钮元素 var btns = document.getElementsByTagName("button"); // btns得到的是伪数组 里面的每一个元素 btns[i] for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function () {
// (1) 我们先把所有的按钮背景颜色去掉 干掉所有人 for (var i = 0; i < btns.length; i++) {
btns[i].style.backgroundColor = ""; } // (2) 然后才让当前的元素背景颜色为pink 留下我自己 this.style.backgroundColor = "pink"; }; } </script>
后记
如果你感觉文章不咋地
//(ㄒoㄒ)//
,就在评论处留言,作者继续改进;o_O???
如果你觉得该文章有一点点用处,可以给作者点个赞;\\*^o^*//
如果你想要和作者一起进步,可以微信扫描二维码,关注前端老L;~~~///(^v^)\\\~~~
谢谢各位读者们啦(^_^)∠※
!!!
边栏推荐
- 五相永磁电机PWM控制系统研究
- transformers中BertPreTrainedModel使用说明
- Digital signal processing experiment I system response and system stability
- Reptile exercises (III)
- Resolved (selenium reports an error) attributeerror: 'webdriver' object has no attribute 'execute_ cdp_ cmd‘
- 一文看懂25个神经网络模型 - 人工神经网络的典型模型
- crontab 执行时间设置
- JSON.parse出现\n时解析错误
- 20220710 leetcode week: move the clip to get the string
- Software testing - learning notes 4
猜你喜欢
随机推荐
Hardware engineer test questions
动态方程博弈相位图
直角坐标系旋转
JSON.parse出现\n时解析错误
Redis e-commerce spike design
Leetcode-11 container with the most water (double pointer, lower_bound, upper bound)
Implement OCR language recognition demo (I) - bottomsheet implementation
读论文:(YOLOv1)You Only Look Once:Unified, Real-Time Object Detection
skywalking的那些配置参数
Day 5 notes sorting
每周推荐短视频:对云计算的弹性算力提出了更高要求
数字信号处理实验三 FIR数字滤波器设计与软件实现
When the MySQL order by field is Chinese
TortoiseSVN Error : Previous operation has not finished; Run 'cleanup' if it was interrupted exception resolution
中文同义句在线转换器 - 中文同义句转换器软件
Supervisor使用了解
How to demonstrate the quality of products in reverse?
Appium automation test foundation - operating wechat applet
ERP能力计划与排产
transformers中BertPreTrainedModel使用说明