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

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

问题描述

我使用 jquery 分页插件,不幸的是它没有设置当前页面的方法从物体外部.我真的研究过这个对象(函数不长),但作为一个 jquery 初学者,我什至找不到事件绑定的方式(显然是通过点击).我不知道如何修改这个函数,所以我可以调用类似的东西:current_page(10) 将当前页面设置为 10.我让其他所有东西都可以用于历史记录(使用更改哈希事件),现在返回加载上一页 OK,但是在视觉上,分页器当然不会移动或更改活动页面.我真的需要一个触发器来实现这一点.

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

你可以在这里试试,设置只是复制演示页面,但实际上我添加的只是.selectPage() 调用上面.为了完全公开,还有 .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天全站免登陆