Control the movement of small squares with keyboard Elements
<HTML> <HEAD> <! -- Code by hongseheike <TITLE> Control of keyboard elements </TITLE> <SCRIPT language = javascript> ns4 = (document. layers )? True: false; ie4 = (document. all )? True: false; function init () {if (ns4) {block = document. blockDiv;} if (ie4) {block = blockDiv. style;} block. xpos = parseInt (block. left); block. active = false; document. onkeydown = keyDown; document. onkeyup = keyUp; if (ns4) {document. captureEvents (Event. KEYDOWN | Event. KEYUP) ;}} function keyDown (e) {if (ns4) {var nkey = e. which; var iekey = 0;} if (ie4) {var iekey = event. keyCode; var nkey = 0;} if (nkey = 97 | iekey = 65 )&&! Block. active) {block. active = true; slide () ;}} function keyUp (e) {if (ns4) {var nkey = e. which; var iekey = 0;} if (ie4) {var iekey = event. keyCode; var nkey = 0;} if (nkey = 97 | iekey = 65) {block. active = false ;}} function slide () {if (block. active) {block. xpos + = 5; block. left = block. xpos; status = block. xpos; setTimeout ("slide ()", 30) ;}} SCRIPT </pead> <BODY onLoad = "init ()"> // Javascript Document <cente R> press the "A" key to slide the square </center> ~ V ~ </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]