how to get the arrow keys on the keyboard to trigger navigation (previous/next page) links within a blog

后端 未结 2 1344
醉梦人生
醉梦人生 2021-02-01 23:42

the script i\'ve pieced together so far looks like this:



        
2条回答
  •  情话喂你
    2021-02-02 00:47

    function leftArrowPressed() {
       // Your stuff here
    }
    
    function rightArrowPressed() {
       // Your stuff here
    }
    
    document.onkeydown = function(evt) {
        evt = evt || window.event;
        switch (evt.keyCode) {
            case 37:
                leftArrowPressed();
                break;
            case 39:
                rightArrowPressed();
                break;
        }
    };
    

提交回复
热议问题