以下是代码:
<html> <head> <script language='javascript'> <!-- function issueCommand(x){ if (document.layers) { if (x.which==99||x.which==67) window.close(); else if (event.keyCode==112||event.keyCode==80) self.print(); else if (event.keyCode==110||event.keyCode==78) alert("Sorry, this is the only song in the List"); } else if (document.all){ if (event.keyCode==99||event.keyCode==67) window.close(); else if (event.keyCode==112||event.keyCode==80) self.print(); else if (event.keyCode==110||event.keyCode==78) alert("Sorry, this is the only song in the List"); } } //--> </script> </head> <body> <script language='javascript'> <!-- if (document.layers) document.captureEvents(Event.KEYPRESS); document.onkeypress=issueCommand --> </script> <font size=6><u>P</u>ress P</font><p> <font size=6><u>N</u>ext One</font><p> <font size=6><u>C</u>lose Window</font><p> </body> </html>
[Ctrl+A 全选 Ctrl+C 复制]
<html> <head> <script language='javascript'> <!-- function issueCommand(x){ if (document.layers) { if (x.which==99||x.which==67) window.close(); else if (event.keyCode==112||event.keyCode==80) self.print(); else if (event.keyCode==110||event.keyCode==78) alert("Sorry, this is the only song in the List"); } else if (document.all){ if (event.keyCode==99||event.keyCode==67) window.close(); else if (event.keyCode==112||event.keyCode==80) self.print(); else if (event.keyCode==110||event.keyCode==78) alert("Sorry, this is the only song in the List"); } } //--> </script> </head> <body> <script language='javascript'> <!-- if (document.layers) document.captureEvents(Event.KEYPRESS); document.onkeypress=issueCommand --> </script> <font size=6><u>P</u>ress P</font><p> <font size=6><u>N</u>ext One</font><p> <font size=6><u>C</u>lose Window</font><p> </body> </html>
[Ctrl+A 全选 Ctrl+C 复制]
博客给出了一段代码,运用JavaScript实现按键功能。代码中定义了issueCommand函数,根据不同按键(如C、P、N)执行关闭窗口、打印、弹出提示等操作,还对不同浏览器环境做了兼容处理。
1044

被折叠的 条评论
为什么被折叠?



