| 
                         //     ulList[i].onmouseover = function () {                     //         // 高亮选中:                     //         //this:当前操作的元素                     //         //=>第一种方法                     //                 //  this.style.background = 'yellow';                     //          //=>第二种方法                     //                 // this.id = 'hover';                     //         //=>第三种方法                     //           //=>设置新样式之前把原有的样式保存起来,this:当前操作的元素也是一个元素对象,有很多内置属性,我们设置一个自定义属性,把原有的样式类信息存储进来 
//           console.dir(this);                                                     //                //=>滑过,简单粗暴的让class等于hover                     //                  this.className = 'hover';                     //             }                     //             ulList[i].onmouseout = function() {                     //                // this.style.background = '';                     //                //    this.id = '';                     //                //=>离开:让其还原为原有的样式(原有的样式可能是bg0,bg1,bg2)                     //                this.className=this.myOldClass; 
//             }                     // }            //=>6.js第五种方式三元运算符三种写法                        //=>第一种写法                         // function changeColor() {                         //     for (var i = 0 ; i< ulList.length; i++){                         //         ulList[i].style.backgroundColor = i % 3 == 0 ? 'lightblue': ((i%3 ==1)?'lightgreen':'lightpink');                         //     }                         // }                         // changeColor();                      //=>第二种写法                         // for (var i = 0; i < ulList.length; i++) {                         //     var n = i % 3;                         //     liColor = ulList[i];                         //        //=>以下两种都可以                         //             // n === 0 ? liColor.style.backgroundColor = 'red' : (n === 1 ? liColor.style.backgroundColor = 'yellow' :                         //           //     liColor.style.backgroundColor = 'pink')                         //=>第三种写法                         //     n === 0 ? liColor.style.backgroundColor='red': n === 1 ?liColor.style.backgroundColor='yellow' : liColor.style.backgroundColor='blue';                         // }              //=>7.js第六种方式                  //=>我们每一组循环一次,在循环体中,我们把当前这一组样式都设置好即可(可能出现当前这一组不够3个,就报错了)                     // var max = ulList.length - 1;                     // for (var i=0;i<ulList.length;i+=3){                     //     ulList[i].style.background='bg0';                     //     i + 1 <= max ? ulList[i+1].style.background='bg1':null;                      //     i + 2 <= max ? ulList[i+2].style.background='bg2':null;                     // }     </script> </body> 
</html> 
运行效果如下: 
到此这篇关于HTML n种方式实现隔行变色的示例代码的文章就介绍到这了,更多相关HTML隔行变色内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!                         (编辑:滁州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |