After this article, the Helper House (www.bkjia.com) is very interesting. I wrote the code provided in the original article of the Web egg, which is very simple. I added some control in actual use, for example, if it disappears after a certain period of time, the variable value is cleared after refresh, and the key value is record again. The principle of the program is to check the key value of the key and execute the specified function when the predefined conditions are met.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Tip: the code can be modified before running!
| Code and comments: Function trick (e ){ If (typeof window. k = "undefined "){ Window. k = "" } Var e = e | event; // Alert (e. keyCode ); If (e. keyCode = 116) window. k = ""; // F5 clear and re-count Window. k + = e. keyCode + ","; If (window. k = "38,38, 40,40, 37,37, 39,39 ,"){ Play (); Window. k = ""; // execute play and clear } }
Function play (){ Var bdy = document. getElementsByTagName ("body") [0]; Var p = bdy. getElementsByTagName ("p") [0]; Var h1 = document. createElement ("h1 "); H1.innerHTML = "Hello !!!!! "; Bdy. className = "bg "; P. style. display = "none "; Bdy. appendChild (h1 ); Window. setTimeout ("clean ()", 5000); // delay cleaning } Function clean () {// restore page Var bdy = document. getElementsByTagName ("body") [0]; Var p = bdy. getElementsByTagName ("p") [0]; Bdy. className = ""; P. style. display = ""; Var h1 = bdy. getElementsByTagName ("h1") [0]; Bdy. removeChild (h1 ); }
Document. onkeydown = trick; // record key value execution function |