100 lines
2.1 KiB
HTML
100 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>tabs</title>
|
|
<style>
|
|
body,ul,li{
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
ul li {
|
|
list-style: none;
|
|
}
|
|
.main{
|
|
width: 400px;
|
|
margin: 100px auto;
|
|
}
|
|
.tabs_title {
|
|
overflow: hidden;
|
|
|
|
}
|
|
.tabs_title li {
|
|
float: left;
|
|
padding: 5px 10px;
|
|
}
|
|
.tabs_content ul {
|
|
padding-left: 10px;
|
|
}
|
|
.tabs_content li {
|
|
display: none;
|
|
}
|
|
.content_on {
|
|
display: block !important;
|
|
}
|
|
.title_on {
|
|
color: red;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<div class="main">
|
|
<div class="tabs_title">
|
|
<ul>
|
|
|
|
</ul>
|
|
</div>
|
|
<div class="tabs_content">
|
|
<ul>
|
|
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
|
var title = [ '公告','论坛','规则','安全','公益' ]
|
|
var content = [ '公告的内容','论坛的内容','规则的内容','安全的内容','公益的内容' ]
|
|
|
|
|
|
|
|
var titleArray = document.querySelectorAll(".tabs_title li");
|
|
var contentArray = document.querySelectorAll(".tabs_content li");
|
|
// function changeTitle (index) {
|
|
|
|
// for (var i =0;i<titleArray.length;i++) {
|
|
// titleArray[i].className = ""
|
|
// contentArray[i].className = ""
|
|
// }
|
|
// titleArray[index].className = "title_on"
|
|
// contentArray[index].className = "content_on"
|
|
// }
|
|
|
|
|
|
function renderli () {
|
|
// 遍历所有元素绑定 onmouseover 事件
|
|
for (let i =0;i<titleArray.length;i++) {
|
|
titleArray[i].onmouseover = function () {
|
|
// 遍历所有元素清除样式
|
|
for (var j =0;j<titleArray.length;j++) {
|
|
titleArray[j].className = ""
|
|
contentArray[j].className = ""
|
|
}
|
|
// 为你悬浮的元素设置样式
|
|
titleArray[i].className = "title_on"
|
|
contentArray[i].className = "content_on"
|
|
}
|
|
}
|
|
}
|
|
|
|
renderli()
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |