jquery history plugin set current page possible?

别等时光非礼了梦想. 提交于 2019-12-01 09:56:30

问题


I use jquery pagination plugin, unfortunately it doesn't have method to set current page from outside the object. I've really looked into this object (the function is not long), but as a jquery beginner I can not even find how the event binds (by click obviously). I have no idea how to modify this function so I can call something like: current_page(10) to set current page to 10. I have everything else working for history (using the change hash event), back now loads previous page OK, but visually the paginator doesn't move or change active page of course. I really need a trigget to make this happen.

I would be very happy if someone at least points me to the part of the function where I can modify this...


回答1:


The pagination plugin actually does have this built-in, it's just in an unconventional and not-obvious way, the key is this bit:

var panel = jQuery(this);
// Attach control functions to the DOM element 
this.selectPage = function(page_id){ pageSelected(page_id);}

This creates a .selectPage() method on the DOM element the pagination links are in, for example in their demo page you'd call it like this:

$("#Pagination")[0].selectPage(9); //0-based, 9 = page 10

You can give it a try here, the setup is just replicating the demo page, but literally all I've added is the .selectPage() call above. In the interest of full disclose there's also .prevPage() and .nextPage() functions available in the same way, e.g. $("#Pagination")[0].nextPage();



来源:https://stackoverflow.com/questions/3522225/jquery-history-plugin-set-current-page-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!