浏览器好像不允许js获取F5这个键的按下事件,应该屏蔽了,这个键太过特殊,猜测可能是,防止用户失去对浏览器的控制?
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <meta charset="utf-8" /> </head> <body onkeypress="checkKey(event)"> dsfsdfasdfasdfa <script type="text/javascript"> function checkKey(event) { keynum = window.event ? event.keyCode : event.which; keychar = String.fromCharCode(keynum); alert(keynum + ':' + keychar); console.log(event); console.log(this) //alert("event"); if (keynum == 116) { alert("想刷新?"); return false; } } </script> </body> </html>