网页真分页js代码该怎么写?
发布于 8 年前 作者 haoning7788 4538 次浏览 来自 分享

真分页这个词对程序猿们来说,并不是一个陌生的词汇,但是如果你是初次学习真分页,或许还是得花点时间小小研究下,下面是之前去转盘网(喜欢的可以看看,也可以进入引擎模式)的真分页js部分代码,html部分的我就不写了,稍微处理下代码就可以使用的,你也可以根据需要灵活变动,千万不要懒惰哦,废话不说了,直接上代码:

function get_param(param){ //这个函数是用来获取url的参数的
 
var query = location.search.substring(1).split('&');
for(var i=0;i<query.length;i++){
var kv = query[i].split('=');
if(kv[0] == param){
return kv[1];
}
}
return null;
}
 
$("#page_down").unbind().bind('click',function(){ //向下翻页
 
temp=get_param("currentPage");
if(temp==null || isNaN(temp)){ //非数字或者无页码
toPage=1;
}
else{
toPage=parseInt(temp)+1;
}
ifnull=$("#ifnull").attr("value");
if(ifnull.length<3){
toPage=1;
}
url="${pageContext.request.contextPath }/funnyPic.do?currentPage="+toPage;
window.location.replace(url);
});
 
$("#home").unbind().bind('click',function(){//回到首页
url="${pageContext.request.contextPath }/funnyPic.do?currentPage=1";
window.location.replace(url);
});
 
$("#page_up").unbind().bind('click',function(){ //向上翻页
temp=get_param("currentPage");
if(temp==null || isNaN(temp)){ //非数字或者无页码
toPage=1;
}
else{
toPage=parseInt(temp)-1;
}
if(toPage<1){
showMessage("亲~第一页了,真不知道往哪走了");
return;
}
ifnull=$("#ifnull").attr("value");
if(ifnull.length<3){
toPage=1;
}
url="${pageContext.request.contextPath }/index.do?currentPage="+toPage;
window.location.replace(url);
});
 
$(".turnPage").unbind().bind('click',function(){//翻页部分的代码
toPage=parseInt($(this).text()+"");
ifnull=$("#ifnull").attr("value");
if(ifnull.length<3){
toPage=1;
}
url="${pageContext.request.contextPath }/funnyPic.do?currentPage="+toPage;
window.location.replace(url);
});

本人建个qq群,欢迎大家一起交流技术, 群号:512245829 喜欢微博的朋友关注:转盘娱乐即可

6 回复

谁给解释下什么叫“真分页”? 分页的话我懂点 1、通过每页的数量和总数量算出页数 2、然后需要确定当前页,通过offset把当前页的东西取出来

@hezhongfeng 有的分页是“假分页”,一次把所有数据从数据库取出来,然后分页其实是用js操作的,但真分页每回取出的数据量是页大小

@haoning7788 谢谢 那么我的处理就是真分页了哈 把所有东西都取出来明显不符合逻辑

@hezhongfeng 是的,之前遇到过这样的情况的,真分页明显是减少了时空代价,但假分页压趴了数据库,累死了浏览器,麻烦了cpu

回到顶部