Capturing ctrl+z key combination in javascript
问题 I am trying to capture ctrl + z key combination in javascript with this code: <html> <head> <title>Untitled Document</title> </head> <body> <script type=\'text/javascript\'> function KeyPress(e) { var evtobj = window.event? event : e //test1 if (evtobj.ctrlKey) alert(\"Ctrl\"); //test2 if (evtobj.keyCode == 122) alert(\"z\"); //test 1 & 2 if (evtobj.keyCode == 122 && evtobj.ctrlKey) alert(\"Ctrl+z\"); } document.onkeypress = KeyPress; </script> </body> </html> Commented line \"test1\"