|
@@ -0,0 +1,82 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+ <style>
|
|
|
+ *{
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+ ul{
|
|
|
+ list-style: none;
|
|
|
+ }
|
|
|
+ #btn{
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+ li{
|
|
|
+ width: 50px;
|
|
|
+ height: 30px;
|
|
|
+ background: aqua;
|
|
|
+ text-align: center;
|
|
|
+ line-height: 30px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ float: left;
|
|
|
+ border-radius: 10px;
|
|
|
+ }
|
|
|
+ #div1{
|
|
|
+ width: 400px;
|
|
|
+ height: 200px;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ }
|
|
|
+ .selected{
|
|
|
+ color: white;
|
|
|
+ background: orange;
|
|
|
+ }
|
|
|
+ .actived{
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+ .select{
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="container">
|
|
|
+ <ul id="btn">
|
|
|
+ <li class="selected">时事</li>
|
|
|
+ <li>新闻</li>
|
|
|
+ <li>体育</li>
|
|
|
+ </ul>
|
|
|
+ <div id="div1">
|
|
|
+ <div class="actived select">时事内容</div>
|
|
|
+ <div class="actived">新闻内容</div>
|
|
|
+ <div class="actived">体育内容</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <script>
|
|
|
+ var btn = document.getElementsByTagName('li')
|
|
|
+ var content = document.getElementsByClassName('actived')
|
|
|
+
|
|
|
+ console.log(btn)
|
|
|
+ console.log(content)
|
|
|
+ for(var i=0;i<btn.length;i++){
|
|
|
+ btn[i].index = i
|
|
|
+ console.log(btn[i].index)
|
|
|
+ btn[i].onclick = function(){
|
|
|
+ for(var j=0;j<btn.length;j++){
|
|
|
+ btn[j].className = ''
|
|
|
+ content[j].className = 'actived'
|
|
|
+
|
|
|
+ }
|
|
|
+ //this = btn[点击哪个是哪个] btn[点击哪个就是哪个].index = 点击哪个就是那个
|
|
|
+ this.className = 'selected'
|
|
|
+ //content[点击哪个就是哪个] = content[btn[点击哪个就是哪个].index] = content[this.index]
|
|
|
+ content[this.index].className = 'actived select'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|