网页ESC使用
来源:互联网 发布:js自动清除缓存 编辑:程序博客网 时间:2024/05/01 12:50
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Demo</title> <script language="JavaScript" type="text/javascript"> function resetEscAndF5(e) { e = e ? e : window.event; actualCode = e.keyCode ? e.keyCode : e.charCode; if(actualCode == 27) { document.getElementById("D1").style.visibility=document.getElementById("D1").style.visibility=="hidden"?"visible":"hidden"; } } function _attachEvent(obj, evt, func) { if(obj.addEventListener) { obj.addEventListener(evt, func, false); } else if(obj.attachEvent) { obj.attachEvent("on" + evt, func); } } _attachEvent(document.documentElement, 'keydown', resetEscAndF5); </script> </head> <body> <div id="D1" style="height: 320px; width: 800px; position: absolute; top: 100px; left: 182px; background-color: #CC0000; visibility:hidden;"> </div> </body></html>