【问题标题】:How can I pass my own parameter to the callback function in JQuery pagination plugin?如何将自己的参数传递给 JQuery 分页插件中的回调函数?
【发布时间】:2011-02-04 03:37:59
【问题描述】:

根据JQuery pagination plugin's文档中回调的定义。它似乎只获取自己的两个参数。那么,我怎样才能将额外的参数传递给回调函数。

回调

一个被调用的回调函数 当用户点击分页时 关联。该函数接收两个 参数:新页面索引和 分页容器(一个 DOM 元素)。 如果回调返回 false,则 事件传播停止。默认 值:函数(){返回假;}。这 回调函数是必不可少的 分页功能!它 应该包含更新您的代码 内容。快速的用户体验 你不应该通过 AJAX 加载内容 在这个函数中。相反,预加载 一些内容页面并在它们之间切换 他们用这个功能。

例如插件使用代码[来自其演示]:

附加分页插件:

$("#News-Pagination").pagination(122, {
    items_per_page:20,
    callback:pageselectCallback
});

回调函数:

    /**
     * Callback function that displays the content.
     *
     * Gets called every time the user clicks on a pagination link.
     *
     * @param {int}page_index New Page index
     * @param {jQuery} jq the container with the pagination links 
     *                 as a jQuery object
     */
     function pageselectCallback(page_index, jq){
       var new_content 
         = $('#hiddenresult div.result:eq(' + page_index + ')').clone();
       $('#Searchresult').empty().append(new_content);
       return false;
     }

非常感谢!!

【问题讨论】:

    标签: jquery pagination


    【解决方案1】:

    使用 JS 中常见的自定义包装函数来实现。

    callback: function(jq1, jq2, ..., jqN) {
      return pageselectCallback(your1, your2, jq1, jq2, ..., jqN);
    }
    

    这里jq1到jqN是jQuery分页插件给的参数,而your1、your2是参数你自己指定。

    重要提示:由于省略号...,以上不是有效的 JS 语法, - 更改以匹配您的情况

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      相关资源
      最近更新 更多