同一页面中的两个 jquery 分页插件似乎不起作用 [英] Two jquery pagination plugin in the same page doesn't seem to work

查看:17
本文介绍了同一页面中的两个 jquery 分页插件似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery分页插件进行分页...如果有一个分页插件对我来说没有问题...但是如果有两个似乎可以工作但另一个似乎不起作用...这里是我的代码,

</div><br/><br/><br/><div id="ResultsDiv">

<div id="PagerDown" class="pager">

我的 jquery 有,

这是我得到的...

替代文字 http://img52.imageshack.us/img52/5618/pagerse.jpg

两者都有效,但查看 pagerup 所选页面是 3PagerDown 显示 1....如何在jquery中的其他寻呼机回调事件上更改一个寻呼机....

使用 mef 的想法似乎行不通...

<head runat="服务器"><title></title><script type="text/javascript" src="jquery.js"></script><link rel="Stylesheet" type="text/css" href="CSS/Main.css"/><script type="text/javascript" src="Javascript/jquery.pagination.js"><script type="text/javascript">$(document).ready(function() {$(".pager").pagination(300, { callback: pagecallback,当前_页面:0,items_per_page: 5,num_display_entries: 5,next_text: '下一个',prev_text: '上一个',num_edge_entries: 1});});函数页面回调(){var paginationClone = $("#Pagination > *").clone(true);$("#Pagination2").empty();paginationClone.appendTo("#Pagination2");}<身体><form id="form1" runat="server"><div><div class="pager" id="分页"><!-- 第一个分页区域的容器-->

<div id="结果"><!-- 显示结果的容器-->

<div class="pager" id="Pagination2"><!-- 第二个分页区域的容器-->

</表单>

解决方案

由于这似乎不受官方支持,这里有一个解决方法 (工作演示).

步骤 1按如下方式创建 HTML 标记:

<div id="结果"><!-- 显示结果的容器-->

<div class="pagination" id="Pagination2"><!-- 第二个分页区域的容器-->

第 2 步 想法:
现在的想法是将分页插件照常与第一个分页 div 一起使用.但另外,我们希望每次发生页面变化时,将第一个分页 div 的所有内容复制到第二个分页 div 中.

步骤 3 调整 pageSelect 回调:
在回调函数的末尾添加以下几行:

var paginationClone = $("#Pagination > *").clone(true);$("#Pagination2").empty();paginationClone.appendTo("#Pagination2");

.clone 调用中包含布尔参数 (withDataAndEvents) 非常重要,否则您的分页副本将不会有任何点击事件.

现在,每次点击分页元素(无论是原版还是副本),页面都会发生变化,分页元素也会相应更新.

I use jquery pagination plugin for paging... If there is one pagination plugin there is no problem for me... But if there is two one seems to work but the other doesn't seem too... Here is my code,

<div id="PagerUp" class="pager">

</div><br /><br /><br />
    <div id="ResultsDiv">

</div>
<div id="PagerDown" class="pager">

</div>

And my jquery has,

<script type="text/javascript">
         var itemsPerPage = 5;
         $(document).ready(function() {
             getRecordspage(0, itemsPerPage);
             var maxvalues = $("#HfId").val();
             $(".pager").pagination(maxvalues, {
                 callback: getRecordspage,
                 current_page: 0,
                 items_per_page: itemsPerPage,
                 num_display_entries: 5,
                 next_text: 'Next',
                 prev_text: 'Prev',
                 num_edge_entries: 1
             });
         });

</script>

Here is what i am getting...

alt text http://img52.imageshack.us/img52/5618/pagerse.jpg

Both works but Look at the pagerup the selected page is 3 but the PagerDown shows 1.... How to change one pager on other pagers callback event in jquery....

EDIT: using mef's idea doesn't seem to work...

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="jquery.js"></script>
    <link rel="Stylesheet" type="text/css" href="CSS/Main.css" />
      <script type="text/javascript" src="Javascript/jquery.pagination.js">
      </script>
    <script type="text/javascript">
        $(document).ready(function() {
            $(".pager").pagination(300, { callback: pagecallback,
                current_page: 0,
                items_per_page: 5,
                num_display_entries: 5,
                next_text: 'Next',
                prev_text: 'Prev',
                num_edge_entries: 1
            });
        });
    function pagecallback() {
        var paginationClone = $("#Pagination > *").clone(true);
        $("#Pagination2").empty();
        paginationClone.appendTo("#Pagination2");
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

<div class="pager" id="pagination">
  <!-- the container for your first pagination area -->
</div>

<div id="results">
  <!-- the container where you show your results -->
</div>

<div class="pager" id="Pagination2">
  <!-- the container for your second pagination area -->
</div>
    </div>
    </form>
</body>
</html>

解决方案

Since this doesn't seem to be officially supported, here is a workaround (working demo).

Step 1 Create your HTML markup as follows:

<div class="pagination" id="Pagination">
  <!-- the container for your first pagination area -->
</div>

<div id="results">
  <!-- the container where you show your results -->
</div>

<div class="pagination" id="Pagination2">
  <!-- the container for your second pagination area -->
</div>

Step 2 The idea:
The idea is now to use the pagination plugin as usual with the first pagination div. But additionally, we want to copy all contents of the first pagination div to the second pagination div every time a page change occurs.

Step 3 Tweak the pageSelect-callback:
Add the following lines at the end of your callback function:

var paginationClone = $("#Pagination > *").clone(true);
$("#Pagination2").empty();
paginationClone.appendTo("#Pagination2");

It is very important to include the boolean parameter (withDataAndEvents) with the .clone call, otherwise the copy of your pagination won't have any click events.

Now, every time you click on a pagination element (regardless if it is the original or the copy), the page will change and the pagination elements will update accordingly.

这篇关于同一页面中的两个 jquery 分页插件似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆