0
4

2 回答 2

1

jsFiddle Live Example

$('#next').click(function() {
    window.open('http://www.stackoverflow.com', '_blank');
});

$('#prev').click(function() {
    window.open('http://www.google.com', '_blank');
});

$(function() {
    $('#next').trigger('click')
})
于 2012-09-03T08:54:13.867 回答
1

I didn't find the exact answer for my question, I would like to post a slightly different and final, well working solution, based on information gathered and peoples' post. Thank you those that replied!

When you construct pagination, I believe, a user would be happy to just click ← Ctrl / Ctrl → to switch in between pages.

The following code has only one improvement - the error occurred on the first an the last page - when there are no next or previous buttons on the page, because you either on the last pagination or the first one, the initial code returned undefined (obviously), so I fixed it and would like to share the final result with those who could be possibly interested:

$(document).keydown(function (event) {
var keycode = event.keyCode ? event.keyCode : event.which;
  if (event.ctrlKey) {
    if (keycode === 39) {
        var nextExists = $('#pagination li.next a').attr('href');
        if (nextExists) window.location.href = $('#pagination li.next a').attr("href");
    }
    if (keycode === 37) {
        var previousExists = $('#pagination li.previous a').attr('href');
        if (previousExists) window.location.href = $('#pagination li.previous a').attr("href");
    }
  }
});
于 2012-09-05T07:52:40.310 回答