網站真分頁js代碼該怎么寫?


真分頁這個詞對程序猿們來說,並不是一個陌生的詞匯,但是如果你是初次學習真分頁,或許還是得花點時間小小研究下,下面是之前去轉盤網(喜歡的可以看看,也可以進入引擎模式)的真分頁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 喜歡微博的朋友關注:轉盤娛樂即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM