代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>列表</title>
<link rel="stylesheet" href="./style/style.css">
<style>
.bigbox{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.list_box{
flex: 1;
overflow-y: auto;
}
.header{
height: 80rem;
width: 100%;
background-color: #DD3635;
display: flex;
align-items: center;
padding-left: 24rem;
padding-right: 24rem;
}
/* .search_box{
width: 57rem;
height: 57rem;
margin-left: 20rem;
} */
.nav{
flex: 1;
overflow-x: auto;
}
.nav ul{
display: flex;
align-items: flex-end;
}
.nav ul li{
color: #FFFFFF;
font-size: 36rem;
margin-right: 34rem;
flex-shrink: 0;
}
.nav ul li.sel{
font-size: 38rem;
font-weight: bold;
color: blue;
/* !important */
}
/* .search_box img{
width: 100%;
} */
.list_box{
padding: 24rem;
}
.list_box ul li{
display: flex;
justify-content: space-between;
height: 200rem;
border-bottom: 1px solid #a5a5a5;
padding-top: 20rem;
padding-bottom: 20rem;
}
.img_box{
width: 228rem;
height: 150rem;
overflow: hidden;
margin-left: 20rem;
}
.img_box>img{
/* width: 100%; */
width: 228rem;
height: 150rem;
}
.title_box{
display: inline-flex;
flex-direction: column;
justify-content: space-between;
}
.title{
color: #222222;
font-size: 34rem;
font-weight: 400;
text-align: justify;
height: 88rem;
overflow: hidden;
width: 454rem;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
}
.time{
color: #A5A5A5;
font-size: 24rem;
}
</style>
</head>
<body>
<div class="bigbox">
<div class="header">
<div class="nav">
<ul>
</ul>
</div>
<div class="search_box">
<img src="./images/search.png" />
</div>
</div>
<div class="list_box">
<ul>
</ul>
</div>
<div class="foot_nav">3</div>
</div>
<script src="./js/ajax.js"></script>
<script>
// 渲染头部新闻分类菜单
var arr = ['军事','财经','NBA','汽车','文化','股票','时政'];
var navUl = document.querySelector('.nav ul');
var navHtml = '';
for(var i=0; i<arr.length; i++){
console.log(arr[i])
navHtml += '<li><a>'+arr[i]+'</a></li>'
}
// console.log(navUl)
navUl.innerHTML = navHtml
// 获取军事新闻列表并渲染
var listbox = document.querySelector('.list_box ul')
var listHtml = ``;
ajax({
url: '/news',
data: {
type: '军事'
},
success: function(res){
for(var i =0; i<res.length; i++){
// 时间处理
var d = new Date(parseInt(res[i].time))
listHtml += ` <li>
<div class="title_box">
<div class="title">${res[i].title}</div>
<div class="time">${res[i].source}-${res[i].type} ${d.getFullYear()}年${d.getMonth()+1}月${d.getDate()}日 </div>
</div>
<div class="img_box">
<img src="${res[i].img}" />
</div>
</li>`
}
listbox.innerHTML = listHtml;
}
})
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。