jQuery的历史插件设置当前页面可能吗? [英] jquery history plugin set current page possible?

查看:104
本文介绍了jQuery的历史插件设置当前页面可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery 分页插件,很遗憾,它没有设置当前页面的方法从物体外面.我确实研究了这个对象(功能不长),但是作为一名jQuery初学者,我什至无法找到事件的绑定方式(显然是通过单击).我不知道如何修改此功能,因此可以调用类似的命令:current_page(10)将当前页面设置为10.我有其他一切用于历史记录(使用change hash事件),现在可以加载上一页,但是显然,分页器不会移动或更改活动页面.我真的需要一个小工具才能做到这一点.

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...

推荐答案

分页插件实际上确实具有此内置功能,只是一种非常规且不明显的方式,关键是位:

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);}

这会在分页链接所在的DOM元素上创建一个.selectPage()方法,例如,在其演示页面中,您可以这样称呼它:

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

您可以在这里尝试,设置只是复制演示页面,但实际上我添加的只是致电上方.为了全面披露,还提供了.prevPage().nextPage()函数以相同的方式提供,例如$("#Pagination")[0].nextPage();

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();

这篇关于jQuery的历史插件设置当前页面可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆