160 lines
3.8 KiB
HTML
160 lines
3.8 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>tabsv2</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
list-style: none;
|
|
}
|
|
|
|
.title {
|
|
display: flex;
|
|
}
|
|
|
|
.title li {
|
|
margin-right: 20px;
|
|
}
|
|
|
|
.title .active {
|
|
color: red;
|
|
}
|
|
|
|
.content li {
|
|
display: none;
|
|
}
|
|
|
|
.content .active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<!-- <ul class="title"></ul>
|
|
<ul class="content"></ul> -->
|
|
|
|
<ul class="title">
|
|
</ul>
|
|
|
|
<ul class="content">
|
|
</ul>
|
|
</body>
|
|
<script>
|
|
var tabsList = [
|
|
{
|
|
title: '社会',
|
|
content: [
|
|
{
|
|
title: '社会新闻',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: '娱乐',
|
|
content: [
|
|
{
|
|
title: '娱乐新闻1',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
},
|
|
{
|
|
title: '娱乐新闻2',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: '体育',
|
|
content: [
|
|
{
|
|
title: '娱乐新闻1',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
},
|
|
{
|
|
title: '体育新闻2',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
},
|
|
{
|
|
title: '体育新闻3',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: '军事',
|
|
content: [
|
|
{
|
|
title: '娱乐新闻1',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
},
|
|
{
|
|
title: '军事新闻2',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
},
|
|
{
|
|
title: '军事新闻3',
|
|
time: '2023',
|
|
text: '主题内容部分'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
var title = $(".title"),
|
|
content = $(".content");
|
|
|
|
function renderTitle() {
|
|
tabsList.forEach((v, i) => {
|
|
title.innerHTML += `<li class=" ${ i == 0 ? 'active' : ''}"> ${v.title}</li>`//三目运算符给第一个添加样式
|
|
content.innerHTML += `<li class="${ i == 0 ? 'active' : ''}">
|
|
${v.content.map(v => {
|
|
return `<p>${v.title}</p>`
|
|
}).toString().replaceAll(",", "")
|
|
}
|
|
</li> `
|
|
})
|
|
bindClick()
|
|
}
|
|
function bindClick() {
|
|
_(".title li").forEach((v,i) => {
|
|
v.onclick = () => {
|
|
_(".title li").forEach((val,index) => {
|
|
//先清空样式,再添加样式
|
|
val.className=""
|
|
_(".content li")[index].className = ""
|
|
})
|
|
v.className = "active"
|
|
_(".content li")[i].className = "active"
|
|
}
|
|
})
|
|
}
|
|
renderTitle()
|
|
|
|
|
|
|
|
function SearchBaidu(text) {
|
|
open(`https://www.baidu.com/s?wd=${text}`)
|
|
}
|
|
function $(className) {
|
|
return document.querySelector(className)
|
|
}
|
|
function _(className) {
|
|
return document.querySelectorAll(className)
|
|
}
|
|
</script>
|
|
|
|
</html> |