💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 自定义属性 ~~~ <script> var aBtn = document.getelebyname('input'); //aBtn[0].abc = 123;//abc即自定义属性给aBtn加了一个属性,也可以进行读写 for(var i = 0;i <aBtn.length;i++){ aBtn[i].abc = 123; aBtn[i].xyz = true; } </script> ~~~ *** 课堂练习-1: 鼠标点击图片发生变化,类似点击桌面图标 ![](https://box.kancloud.cn/1137aae62718f59245623004c81c5a07_74x104.png) ~~~ <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> ul,li{padding:0;margin:0;list-style: none;} li{width:70px;height:70px;float:left;background: url(img/notactive.png) no-repeat;margin-right:10px;} </style> <script type="text/javascript"> window.onload = function(){ var oUl = document.getElementById('list'); var aLi = oUl.getElementsByTagName('li'); for(var i = 0;i < aLi.length;i++){ // 自定义属性-每个li身上自己有一个开关 aLi[i].onOff = true; aLi[i].onclick = function(){ if(this.onOff){ this.style.background = 'url(img/active.png) no-repeat'; }else{ this.style.background = 'url(img/notactive.png) no-repeat'; } this.onOff = !this.onOff; } } } </script> </head> <body> <ul id="list"> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </body> </html> ~~~ 课堂练习-2 点击按钮实现图片的切换 *** 课堂作业-1:带缩略图的图片切换 ![](https://box.kancloud.cn/0ac32ff6c708f09eaaae623874c3ac57_712x568.gif) *** [图片素材下载](https://pan.baidu.com/s/11Luvx0SiX71Zk01lpSUS_g)