123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <!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;
- }
- #btn li {
- width: 50px;
- height: 30px;
- background: aquamarine;
- text-align: center;
- line-height: 30px;
- border: 1px solid #CCC;
- border-radius: 10px;
- float: left;
- }
- #btn .selected{
- background: orange;
- color: white;
- }
- #div1{
- width: 350px;
- height: 200px;
- border: 1px solid #ccc;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <ul id="btn">
- <li class="selected">时事</li>
- <li>新闻</li>
- <li>体育</li>
- </ul>
- <div id="div1">
- <div>时事内容</div>
- <div>新闻内容</div>
- <div>体育内容</div>
- </div>
- </div>
- <script>
- var btn = document.getElementById('btn')
- var btns = btn.getElementsByTagName('li')
- for(var i=0;i<btns.length;i++){
- btns[i].onclick = function(){
- //this 点谁就是谁
- for(var j=0;j<btns.length;j++){
- btns[j].className = ''
- }
- this.className = 'selected'
- }
- }
-
- </script>
- </body>
- </html>
|