博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery插件开发1:分页条
阅读量:7097 次
发布时间:2019-06-28

本文共 4159 字,大约阅读时间需要 13 分钟。

hot3.png

               

定义三个文件:demo1.html/demo1.js/demo1.css  还有引入jQuery库:jquery-3.2.1.js

1. demo1.html

分页插件

2. demo1.js

(function () {    //默认值    var curPage = 1;    var showN = 5;    var total = 20;    //给jQuery对象的原型添加方法    jQuery.fn.pageInit = function (curPTemp,showNTemp,totalPTemp) {        curPage = curPTemp;        showN = showNTemp;        total = totalPTemp;        callback();    };    //回调函数    function callback() {        //根据初始化获取的参数进行制作UI        var str = '';        for(var i=0;i
'; } str = '
  • 上一页
  • ' + str + '
  • 下一页
  • '; var page = '
      ' + str +'
    '; $('#pageDiv').html(page); //第一次起来当前的页在最左边,高亮。 $("#pageDiv a").eq(1).css("background-color", "green"); $('#pageShow').text(curPage.toString()); //给页码添加点击的监听函数 $('#pageDiv a').click(function () { var temp = $(this).text(); //直接点击一个页码的操作 if(temp !== '下一页' && temp!== '上一页' ){ $('#pageDiv a').css("background-color","darkblue"); $(this).css("background-color","green"); $('#pageShow').text(temp); curPage = parseInt(temp); } //上一页的操作 if(temp === '上一页') { if (curPage == 1 ) { $('#pageShow').text("首页"); }else { if (curPage <= parseInt($("#pageDiv a").eq(1).text())) { $("#pageDiv a").each(function () { var temp = $(this).text(); if (temp !== '下一页' && temp !== '上一页') { $(this).text((parseInt(temp)-1).toString()); } }); curPage = parseInt($("#pageDiv a").eq(1).text()); console.log("\n " + curPage); $('#pageShow').text(curPage.toString()); } else { $("#pageDiv a").each(function () { if ((curPage - 1).toString() === $(this).text()) { $('#pageDiv a').css("background-color", "darkblue"); $(this).css("background-color", "green"); } }); curPage -= 1; $('#pageShow').text(curPage.toString()); } } } //下一页的操作 if(temp === '下一页') { if (curPage >= total) { $('#pageShow').text("末页"); } else { if (parseInt($("#pageDiv a").eq(-2).text()) <= curPage) { $("#pageDiv a").each(function () { var temp = $(this).text(); if (temp !== '下一页' && temp !== '上一页') { $(this).text((parseInt(temp) + 1).toString()); } curPage = parseInt($("#pageDiv a").eq(-2).text()); $('#pageShow').text(curPage.toString()); }); }else { $("#pageDiv a").each(function () { if ((curPage + 1).toString() === $(this).text()) { $('#pageDiv a').css("background-color", "darkblue"); $(this).css("background-color", "green"); } }); curPage += 1; $('#pageShow').text(curPage.toString()); } } } }); }}());

    3. demo1.css

    #pageDiv a,#pageDiv li{    float: left;    height: 30px;    width: 90px;    list-style: none;    border-style: solid;    text-align: center;    color: white;    background-color: darkblue;    text-decoration:none;}#pageShow{    text-align: center;    height: 400px;    font-size: 15em;}#pageDiv{    text-align: center;    background-color: yellow;    clear: both;    margin-left: 300px;}

                  

                     

     

     

    转载于:https://my.oschina.net/u/3697586/blog/1555683

    你可能感兴趣的文章
    假设动态运行java文字,当在脚本式配置,这是非常方便的
    查看>>
    android4.0 的图库Gallery2代码分析(三) 之Applition的初始化准备
    查看>>
    SOM自组织映射网络 教程
    查看>>
    lintcode:寻找旋转排序数组中的最小值 II
    查看>>
    maven项目配置Jetty服务器
    查看>>
    树莓派学习笔记——交叉编译练习之SQLite3安装
    查看>>
    android stuido build 慢的解决办法
    查看>>
    Eclipse 插件安装方法和插件加载失败解决办法
    查看>>
    第四节:教你如何快速让浏览器兼容ES6特性
    查看>>
    C#使用IrisSkin2.dll美化WinForm程序界面
    查看>>
    Appium移动自动化测试(四)--one demo
    查看>>
    nginx配置location总结及rewrite规则写法
    查看>>
    python 登陆接口
    查看>>
    RedHat7 部署ELK日志分析系统
    查看>>
    DS实验题 Missile
    查看>>
    微信上 网页图片点击全屏放大
    查看>>
    jquery获取css颜色值返回RGB应用
    查看>>
    (void __user *)arg 中__user的作用
    查看>>
    APACHE REWRITE ? 匹配问号的写法
    查看>>
    如何跳出页面的Frame框架
    查看>>