开发者

jQuery keypress - How do I map the 0 number pad key to browser back function?

开发者 https://www.devze.com 2023-01-15 10:14 出处:网络
I\'m making a simple UI demo and need 开发者_如何学运维to assign the 0 on the keypad (or perhaps the ESC key in the future) to the back function of a browser.

I'm making a simple UI demo and need 开发者_如何学运维to assign the 0 on the keypad (or perhaps the ESC key in the future) to the back function of a browser.

I've found a few keypress tutorials that deal with specific requirements but none that seems to fit mine. Any advice would be appreciated!


$('body').keypress(function(event) {
    if(event.which == "48" || event.which == "96"){
     alert('number 0 has been pressed');
    }
});​


I may not have the right selector...someone please fix if I have that bit wrong (might be $(window)). Otherwise, you should do something like this.

$(document.documentElement).keyup(function (event) {
   if (event.keyCode == 30) {
     history.back();
   }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消