123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <!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>
- * {
- margin: 0;
- padding: 0;
- list-style: none;
- text-decoration: none;
- box-sizing: border-box;
- }
- #container {
- width: 482px;
- height: 420px;
- margin: 100px auto;
- border: 1px solid #000;
- }
- #list {
- overflow: hidden;
- }
- #list li {
- width: 120px;
- height: 80px;
- text-align: center;
- line-height: 80px;
- float: left;
- border: 1px solid #f00;
- }
- .selected {
- color: #ff0;
- background: #f00;
- }
- .choose {
- display:none;
- }
- .active {
- width: 482px;
- height: 300px;
- color: purple;
- font-weight: bold;
- text-align: center;
- line-height: 300px;
- display: block;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <ul id="list">
- <li class="selected">用户管理</li>
- <li>配置管理</li>
- <li>角色管理</li>
- <li>定时任务补</li>
- </ul>
- <div id="main">
- <div class="choose active">用户管理</div>
- <div class="choose">配置管理</div>
- <div class="choose">角色管理</div>
- <div class="choose">定时任务补</div>
- </div>
- </div>
- <script>
- var list = document.querySelectorAll("ul li");
- var main = document.querySelectorAll(".choose");
- console.log(list,main)
- for(var i=0;i<list.length;i++) {
- // console.log(i);
- // 自定义一个属性下标 存储 点击下标
- list[i].index = i;
- list[i].onclick = function() {
- // 点击事件时 this指向当前点击对象
- // console.log(list[i]);
- console.log(this.index)
- for(var j=0;j<main.length;j++) {
- list[j].className = "";
- main[j].className = "choose";
- }
- list[this.index].className = "selected";
- main[this.index].className = "choose active";
- }
- }
- </script>
- </body>
- </html>
|