jQuery 键盘导航 –向左和向右后退和前进一页
我希望用户在按键盘上的向左或向右时能够加载下一页或上一页。每个页面的下一个和上一个链接包含在两个按钮中。
html...
<a href="/page-link-prev" class="prev button">< Prev</a>
<a href="/page-link-next" class="next button">Next ></a>
我发现一些 jquery 会注册正确的按键,但不会明显更改 url,它只是显示警报。
$(function() {
$(document).keyup(function(e) {
switch(e.keyCode) {
case 37 : alert('You pressed Left'); break;
case 39 : alert('You pressed Right'); break;
}
});
});
I'd like the user to be able to load the next or previous page when they press left or right on the keyboard. The next and previous links for each page are contained within two buttons.
The html...
<a href="/page-link-prev" class="prev button">< Prev</a>
<a href="/page-link-next" class="next button">Next ></a>
Some jquery I found that registers the right key presses, but doesn't change the url obviously, it just shows an alert.
$(function() {
$(document).keyup(function(e) {
switch(e.keyCode) {
case 37 : alert('You pressed Left'); break;
case 39 : alert('You pressed Right'); break;
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
.load()
来从 URL 加载到页面的一部分。我假设您有一个特定的
div
您想要刷新页面内容,并且您不想刷新整个页面或者,如果您想刷新整个页面,您可以使用
window.location
您可以将
#page
替换为您要刷新的元素。You can use
.load()
to load from a URL to a portion of the page.I'm assuming you have a specific
div
you want to refresh w page contents, and you don't want to refresh the entire pageOr, if you want to refresh the entire page you can use
window.location
You can replace
#page
with the element you are refreshing.我认为你必须像这样使用窗口对象的位置属性:
或者你可以触发锚点的 jQuery 对象上的单击事件。
I think you have to use the location property of the window object like this:
Or you can trigger the click event on the jQuery object of your anchor.