1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| <!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> * { padding: 0; margin: 0; }
.tab { margin: 200px auto; width: 600px; }
.tab_list { height: 40px; border: 1px solid #ccc; background-color: #f1f1f1; }
ul { list-style: none; }
li { float: left; cursor: pointer; text-align: center; line-height: 40px; padding: 0 20px; }
.active { background-color: #c81623; color: #fff; }
.item { display: none; }
.model { width: 100%; height: 200px; text-align: center; line-height: 200px; } </style> </head>
<body> <div class="tab"> <div class="tab_list"> <ul> <li class="active">模块01</li> <li>模块02</li> <li>模块03</li> <li>模块04</li> <li>模块05</li> </ul> </div> <div class="tab_content"> <div class="item model" style="display: block;background-color: skyblue;">模块01</div> <div class="item model">模块02</div> <div class="item model">模块03</div> <div class="item model">模块04</div> <div class="item model">模块05</div> </div> </div> <script> var choice= document.querySelector('ul').children var item = document.querySelectorAll('.item')
for (var i = 0; i < choice.length; i++) { choice[i].setAttribute('index', i)
choice[i].onclick = function () {
for (var i = 0; i < choice.length; i++) { choice[i].className = ' ' } this.className = 'active'
function color() { var arrNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'] var newArr = arrNum.join(''); var str = '#'; for (var i = 0; i < 6; i++) { var j = Math.floor(Math.random() * arrNum.length); str += newArr[j] } return str }
var index = this.getAttribute('index') for (var i = 0; i < item.length; i++) { item[i].style.display = 'none' } item[index].style.backgroundColor=color() item[index].style.display = 'block' } } </script> </body>
</html>
|