代码拉取完成,页面将自动刷新
<!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>博客列表</title>
<link rel="stylesheet" href="css/list.css">
<link rel="stylesheet" href="css/blog_list.css">
<script src="js/jquery.min.js"></script>
<style>
.nav{
position: fixed;
top: 0;
left: 0;
right: 0;
height: 50px;
}
.container{
padding-top: 80px;
height: auto;
}
.container-right{
width: auto;
}
.blog-pagnation-wrapper{
height: 40px;
margin: 16px 0;
text-align: center;
}
.blog-pagnation-item{
display: inline-block;
padding: 8px;
border: 1px solid #d0d0d5;
color: #333;
}
.blog-pagnation-item:hover{
background: #4e4eeb;
color: #fff;
}
.blog-pagnation-item.actvie{
background: #4e4eeb;
color: #fff;
}
</style>
</head>
<body>
<!-- 导航栏 -->
<div class="nav">
<img src="img/logo2.jpg" alt="">
<span class="title">我的博客系统</span>
<!-- 用来占据中间位置 -->
<span class="spacer"></span>
<a href="blog_list.html">主页</a>
<a href="blog_add.html">写博客</a>
<a href="javascript:logout()">退出</a>
<!-- <a href="#">注销</a> -->
</div>
<!-- 版心 -->
<!-- 版心 -->
<div class="container">
<!-- 右侧内容详情 -->
<div class="container-right" style="width: 100%;">
<div id="artListDiv">
</div>
<hr>
<div class="blog-pagnation-wrapper">
<button onclick="goFirstPage()" class="blog-pagnation-item">首页</button>
<button onclick="goBeforePage()" class="blog-pagnation-item">上一页</button>
<button onclick="goNextPage()" class="blog-pagnation-item">下一页</button>
<button onclick="goLastPage()" class="blog-pagnation-item">末页</button>
</div>
</div>
</div>
<script>
function logout() {
if (confirm("是否退出")) {
jQuery.ajax({
url:'/user/logout',
type:'post',
success: function(body) {
if (body != null && body.code == 200) {
location.href = "/login.html";
}
}
})
}
}
function getParamValue(key) {
var param = location.search;
if (param.length > 1) {
param = location.search.substring(1);
} else {
return "";
}
var paramArr = param.split("&");
for (var i = 0; i < param.length; i++) {
var item = paramArr[i];
var kv = item.split("=");
if (kv[0] == key) {
return kv[1];
}
}
return "";
}
var lastPage = 0;
var page = 1;
var size = 2; // 数据量
// 获取url里的页码
page = (getParamValue("page") == "" ? 1 : getParamValue("page"));
function initPage() {
jQuery.ajax({
type:'post',
url:'art/listByPage',
data:{"page":page,"size":size},
success:function(result) {
console.log(result.data)
console.log(result.data.length);
if(result!=null && result.data.length > 0){
lastPage = result.code;
var artListHtml = "";
for(var i=0;i<result.data.length;i++){
var articleinfo = result.data[i];
artListHtml +='<div class="blog">';
artListHtml +='<div class="title">'+articleinfo.title+'</div>';
artListHtml +='<div class="date">'+articleinfo.updatetime+'</div>';
artListHtml +='<div class="desc">'+articleinfo.content+'</div>';
artListHtml +='<a href="blog_content.html?id='+ articleinfo.id
+'" class="detail">查看全文 >></a>';
artListHtml +='</div>';
}
jQuery("#artListDiv").html(artListHtml);
// pcount = result.data.pcount;
} else {
alert("无数据");
location.href="blog_list.html";
}
}
})
}
initPage();
// 获取数据
// 首页 尾页
function goFirstPage() {
location.href = "blog_list.html";
}
function goBeforePage() {
if (page <= 1) {
return ;
}
page = parseInt(page) - 1;
location.href = "blog_list.html?page="+page;
}
function goLastPage() {
if (page >= lastPage) {
return;
}
location.href = "blog_list.html?page="+lastPage;
}
function goNextPage() {
if (page >= lastPage) {
return;
}
page = parseInt(page) + 1;
location.href = "blog_list.html?page="+page;
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。