Keyboard Events

How can I name an event clickfor a link when the keyboard button is pressed?

I would like to call the next / previous page to Ctrl+ / Ctrl+

+3
source share
5 answers
$(document).keydown(function(e) {
  if(e.ctrlKey){
     if(e.keyCode == 37){
        //ctrl + leftbutton pressed
        $("a.prevButton").trigger("click");
     }else if(e.keyCode == 39){
        //ctrl + rightbutton pressed
        $("a.nextButton").trigger("click");
     }
  }
});

live violin

+5
source

You can try

$(document).bind("keydown", function(e) {
  if (e.ctrlKey) {
    if(e.keyCode == 37) {
        document.getElementById("prevButton").click();
    }
    else if(e.keyCode == 39) {
        document.getElementById("nextButton").click();
    }
  }
});

code 37 for the left arrow and code 39 for the right arrow

+1
source

, jquery.hotkeys, : http://github.com/tzuryby/jquery.hotkeys. , , .

[ : . .]

+1

jQuery, : http://plugins.jquery.com/project/hotkeys.

:

<script type="text/javascript">
        $(document).ready(function(){
            shortcut("Ctrl+Right",function() {
            document.getElementById("your next button ID").click();
        });
        shortcut("Ctrl+Left",function() {
        document.getElementById("your prev button ID").click();
        });
    });
</script>
+1

, w/jQuery [ , ).

javascript document.getElementById. href, .href. , href → document.location = href

, action form.submit()

0

Source: https://habr.com/ru/post/1768570/


All Articles