本文实例为大家分享了Javascript实现多层颜色选项卡嵌套的具体代码,供大家参考,具体内容如下
这是学Javascript时候的一个作业,如果没有思路还是挺有难度的,但是思路正确的话一步一步来就很简单做出来了。
实现效果
HTML部分代码
- a
- b
- c
- d
- a1
- a2
- a3
- a4
- b1
- b2
- b3
- b4
- c1
- c2
- c3
- c4
- c5
- c6
- d1
- d2
- d3
- d4
css部分代码
* { margin: 0px; padding: 0px; list-style: none; text-decoration: none; } .box { width: 800px; border: 1px solid #000000; margin: 20px auto; background: blue; } .box:after { content: ""; display: block; clear: both; } #leftBox { float: left } #rightBox { float: left; } #leftBox li { width: 200px; height: 89px; background: red; margin-bottom: 2px; color: #fff; font: 50px/89px "黑体"; text-align: center; } #rightBox div { display: none; } #rightBox .active { display: block; } #rightBox a { display: block; width: 600px; height: 325px; background: #0F0; font-size: 100px; color: #000; text-align: center; text-decoration: none; line-height: 360px; } .tabUl { display: table; width: 100%; } .tabUl li { display: table-cell; background: #909; color: #fff; font-size: 20px; text-align: center; height: 40px; line-height: 40px; border-right: 2px solid #03C; cursor: pointer; } .tabUl li.hover { background: #fff; color: #000; } #leftBox .active { background: yellow; color: #000; }
Javascript实现代码
思路:鼠标移入左边的每个li后,都会改变他的颜色,所以只需要改变class名,同时右边也会显示对于的div,有对应的话一般都会用到自定义索引值和this…
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



