根据JQuery pagination plugin's中callback的定义文件。看起来它只获取了自己的两个参数。那么,如何将额外的参数传递给回调函数。
callback
A callback function that is called when a user clicks on a pagination link. The function receives two parameters: the new page index and the pagination container (a DOM element). If the callback returns false, the event propagation is stopped. Default value: function(){return false;}. This callback function is essential for the functionality of the pagination! It should contain code that updates your content. For a fast user experience you should NOT load content via AJAX in this function. Instead, pre-load some content pages and switch between them with this function.
例如插件使用代码[来自其演示]:
附加分页插件:
$("#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;
}
非常感谢!!
最佳答案
使用自定义包装函数(这在 JS 中很常见)来实现这一点。
callback: function(jq1, jq2, ..., jqN) {
return pageselectCallback(your1, your2, jq1, jq2, ..., jqN);
}
这里jq1到jqN是jQuery分页插件给出的参数,而your1、your2是参数您自己指定。
重要提示:由于省略号,上述内容不是有效的 JS 语法 ..., - 请根据您的情况进行更改
关于jquery - 如何将自己的参数传递给 JQuery 分页插件中的回调函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4894332/