|
@@ -0,0 +1,107 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+ <style>
|
|
|
+ body,ul{
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+ li{
|
|
|
+ list-style: none;
|
|
|
+ }
|
|
|
+ .clearfix::after{
|
|
|
+ content: "";
|
|
|
+ display: block;
|
|
|
+ clear: both;
|
|
|
+ }
|
|
|
+ .box{
|
|
|
+ width: 600px;
|
|
|
+ height: 300px;
|
|
|
+ border:1px solid black;
|
|
|
+ margin: 100px auto;
|
|
|
+ }
|
|
|
+ .nav-content{
|
|
|
+ height: 50px;
|
|
|
+ background-color: black;
|
|
|
+ }
|
|
|
+ .nav-content li{
|
|
|
+ float: left;
|
|
|
+ color: #fff;
|
|
|
+ padding: 0 20px;
|
|
|
+ height: 50px;
|
|
|
+ line-height: 50px;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .nav-content .active{
|
|
|
+ background-color: #aaa;
|
|
|
+ color: black;
|
|
|
+ }
|
|
|
+ .info-content{
|
|
|
+ padding: 20px;
|
|
|
+ }
|
|
|
+ .info-content > div{
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+ .info-content .active{
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <div class="box">
|
|
|
+ <div class="nav-content">
|
|
|
+ <ul class="clearfix">
|
|
|
+ <li class="active">第一节课</li>
|
|
|
+ <li >第二节课</li>
|
|
|
+ <li>第三节课</li>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ <div class="info-content">
|
|
|
+ <div class="active">
|
|
|
+ 第一节课内容
|
|
|
+ 第一节课内容
|
|
|
+ 第一节课内容
|
|
|
+ 第一节课内容
|
|
|
+ </div>
|
|
|
+ <div class="">
|
|
|
+ 第二节课内容
|
|
|
+ 第二节课内容
|
|
|
+ 第二节课内容
|
|
|
+ 第二节课内容
|
|
|
+ </div>
|
|
|
+ <div class="">
|
|
|
+ 第三节课内容
|
|
|
+ 第三节课内容
|
|
|
+ 第三节课内容
|
|
|
+ 第三节课内容
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <script>
|
|
|
+ var liBtn = document.getElementsByTagName("li");
|
|
|
+ var contentArr = document.getElementsByClassName("info-content")[0].getElementsByTagName("div");
|
|
|
+ console.log(contentArr)
|
|
|
+ // 循环绑定鼠标移入事件
|
|
|
+ for(var i=0;i<liBtn.length;i++){
|
|
|
+ // 创建新属性保持索引值
|
|
|
+ liBtn[i].index = i;
|
|
|
+ liBtn[i].onmouseenter = function(){
|
|
|
+ // 循环清除所有标签按钮的选中状态
|
|
|
+ for(var j=0;j<liBtn.length;j++){
|
|
|
+ liBtn[j].setAttribute("class","");
|
|
|
+ contentArr[j].setAttribute("class","");
|
|
|
+ }
|
|
|
+ // 仅给当前按钮加入选中状态
|
|
|
+ this.setAttribute("class","active");
|
|
|
+ contentArr[this.index].setAttribute("class","active");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|