导航首页 » 技术教程 » jQuery simplePage+AJAX plus分页插件用法实例
全站头部文字 我要出现在这里
jQuery simplePage+AJAX plus分页插件用法实例 336 2024-03-11   

本文实例讲述了jQuery simplePage+AJAX plus分页插件。分享给大家供大家参考,具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>simplePage</title>
<style type="text/css">
html,body{ margin:0 auto; text-align:center; }
.main{ font:12px/24px "Microsoft YaHei"; height:1000px; }
#page{ margin:100px auto; width:960px; text-align:center; }
#page a{ text-decoration:none; display:inline-block; height:24px; padding:0 8px; border-radius:3px; background-color:#DEF39E; color:#8CAC2C; text-align:center; margin:0 2px; }
#page a:hover,#page .now{ background-color:#8CAC2C; color:#fff; transition:all .5s ease 0s; }
</style>
</head>
<body>
<div class="main">
  <div id="page">
    < 
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">上一页</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">4</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">5</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html" class="now">6</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">7</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">8</a>
    <a href="http://www.gimoo.net/t/1903/5c989891d8858.html">下一页</a>
     -->
  </div>
  <div class="back"></div>
</div>
<script type="text/javascript" src="http://www.gimoo.net/t/1903/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
  $.simplePage({
    obj : "#page",
    nowNum : 1,
    allNum : 20,
    callBack : function(now, all){
      $(".back").html(now + "-" + all);
    }
  });
});
/*!
 * jQuery simple page plus v1.0
 * http://t.qq.com/websole 
 * Author:sole
 * Mail:macore@163.com
 * Created:2012/10/31
 * Copyright 2012 - http://t.qq.com/websole 
*/
$.extend({
  //obj:分页对象; noeNum:当前页; allNum:总页数; callBack:回调函数
  simplePage : function(opt){
    if(!opt.obj){ return false; };
    var obj = $(opt.obj); 
    var nowNum = opt.nowNum || 1; 
    var allNum = opt.allNum || 5; 
    var callBack = opt.callBack || function(){};
    var apd_ele = "";
    function ele(num, cls){
      var str = "";
      if(cls){
        str = "<a href='http://www.gimoo.net/t/1903/5c989891d8858.html"+num+"' class='"+cls+"'>"+num+"</a>";
      }else{
        str = "<a href='http://www.gimoo.net/t/1903/5c989891d8858.html"+num+"'>"+num+"</a>";
      }
      return str;
    }
    if(nowNum > 1){
      apd_ele = "<a href='http://www.gimoo.net/t/1903/5c989891d8858.html"+ ( nowNum - 1 ) +"'>上一页</a>";
      obj.append(apd_ele);
    }
    if(allNum <= 5){
      for(var i=1; i<=allNum; i++){
        if(nowNum == i){
          apd_ele = ele(i, "now");
        }else{
          apd_ele = ele(i);
        }
        obj.append(apd_ele);
      }
    }else{
      for(var i=1; i<=5; i++){
        if(nowNum == 1 || nowNum == 2){
          if(nowNum == i){
            apd_ele = ele(i, "now");
          }else{
            apd_ele = ele(i);
          }
        }else if( (allNum - nowNum) == 0 || (allNum - nowNum) == 1 ){
          if( (allNum - nowNum) == 0 && i == 5){
            apd_ele = ele( (allNum - 5 + i), "now");
          }else if( (allNum - nowNum) == 1 && i == 4){
            apd_ele = ele( (allNum - 5 + i), "now");
          }else{
            apd_ele = ele( allNum - 5 + i );
          }
        }else{
          if(i == 3){
            apd_ele = ele(nowNum-3+i, "now");
          }else{
            apd_ele = ele(nowNum-3+i);
          }
        }
        obj.append(apd_ele);
      }
    }
    if((allNum - nowNum) >= 1){
      apd_ele = "<a href='http://www.gimoo.net/t/1903/5c989891d8858.html"+ ( nowNum + 1 ) +"'>下一页</a>";
      obj.append(apd_ele);
    }
    callBack(nowNum, allNum);
    obj.find("a").click(function(){
      var nowNum = parseInt($(this).attr("href").substring(1));
      obj.html("");
      $.simplePage({
        obj : "#page",
        nowNum : nowNum,
        allNum : allNum,
        callBack :callBack
      });
      return false;
    });
  }
});
</script>
</body>
</html>

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery常用插件及用法总结》、《jquery中Ajax用法总结》及《jquery常用操作技巧汇总》

希望本文所述对大家jQuery程序设计有所帮助。



!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103