简体   繁体   中英

Arrow keys keyboard navigation with Jquery

In Jquery I would like to know how to trigger/click an a href... link that's within a .php page. This page is dynamically generating two links that I'd like to trigger using left and right keyboard arrow keys for paging next and back through a site. The links are two images within two divs. I attempted to use this but was unable to get to work due to how the links are being created.

I could do something like this :

$(document).keydown(function(e){
    if (e.keyCode == 37) { 
       alert( "left pressed" );
       return false;
    }
});

Character codes:

37 - left

38 - up

39 - right

40 - down

$('a').trigger('click');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM