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();
}
});
精彩评论