Files
ClassContent/历届学生/逯帅帅/项目开发/学生项目/谢文军/demo1/page/tabs2.html
2024-09-27 02:06:13 +08:00

149 lines
3.5 KiB
HTML

<!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>tabs切换</title>
<style>
html,
body,
div,
ul,
li,
h1,
h2,
h3,
h4,
h5,
h6,
p,
dl,
dt,
dd,
ol,
form,
input,
textarea,
th,
td,
select {
margin: 0;
padding: 0;
list-style: none;
}
.title {
height: 45px;
display: flex;
align-items: center;
justify-content: space-around;
}
.show_title{
color: red;
}
.content li{
display: none;
}
.show_content{
display: inline-block !important;
}
</style>
</head>
<body>
<div class="tabs">
<ul class="title">
</ul>
<ul class="content">
</ul>
</div>
</body>
<script>
var title = document.querySelector(".title");
var content = document.querySelector(".content");
var tabs = [
{
title: '推荐',
list: [
{
title : '推荐的内容1',
time: '2021-03-05'
},
{
title : '推荐的内容2',
time: '2021-03-05'
}
]
},
{
title: '游戏',
list: [
{
title : '游戏的内容1',
time: '2021-03-05'
},
{
title : '游戏的内容2',
time: '2021-03-05'
}
]
},
{
title: '热点',
list: [
{
title : '热点的内容1',
time: '2021-03-05'
},
{
title : '热点的内容2',
time: '2021-03-05'
}
]
}
];
// function RenderTitle () {
// tabs.forEach(function (v,i){
// title.innerHTML += `<li class="${ i == 0 ? 'show_title' : ''}">${v.title}</li>`
// })
// }
// function RenderContent () {
// tabs.forEach(function (v,i){
// content.innerHTML += `<li class="${ i == 0 ? 'show_content' : ''}">${
// (
// v.list.map(function (item) {
// return `<p>${item.title}</p>`
// }).toString().replace(/,/g, "")
// )
// }</li>`
// })
// }
// function changeTabs() {
// var title = document.querySelectorAll(".title li")
// console.log("title",title);
// var content = document.querySelectorAll(".content li")
// title.forEach(function (vao,index) {
// // console.log(vao)
// vao.onclick = function () {
// // console.log(vao)
// title.forEach(function (asd,bb) {
// asd.classList.remove("show_title")
// content[bb].classList.remove("show_content")
// })
// vao.classList.add("show_title");
// content[index].classList.add("show_content")
// }
// })
// }
// RenderTitle();
// RenderContent();
// changeTabs()
</script>
</html>