Onclick=onmouseup+onmousedown
Onkeypress=onkeydown+onkeyup
Keycod (key value, each key on the keyboard corresponds to a unique value)
Offset
Offsetwidth,offsetleft,offsetheight ... Represents the actual value of the
Getting the value of the keyboard requires an event object, and Firefox uses an EV
Keyboard controls the movement of Div
<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">#div1 {width:100px; height:100px; background: #CCC; position:absolute;}</style><meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/><title> Untitled Document </title><script>Document.onkeydown=function (EV) {varoevent=ev| |Event; varOdiv=document.getelementbyid ('Div1'); //←37//Right if(oevent.keycode==Panax Notoginseng) {ODiv.style.left=odiv.offsetleft-Ten+'px'; } Else if(oevent.keycode== the) {ODiv.style.left=odiv.offsetleft+Ten+'px'; }};</script>"Div1"></div></body>Question: For example, in a tank war game, after pressing the arrow keys, the tank should continue to move, rather than move first, then pause, and then move on. How to solve this small problem? Keyboard Event Acquisition: Ctrl+enter message in fact, the function of keyboard events and mouse events is consistent, the function content is identical.1<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">2"http://www.w3.org/1999/xhtml">34<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>5<title> Untitled Document </title>6<script>7Window.onload=function ()8 {9 varObtn=document.getelementbyid ('BTN1');Ten varOtxt1=document.getelementbyid ('txt1'); One varOtxt2=document.getelementbyid ('txt2'); A -obtn.onclick=function () - { theOtxt1.value+=otxt2.value+'\ n'; -Otxt2.value="'; - }; - +otxt2.onkeydown=function (EV)// Remember: is an event added on the basis of a text box - { + varoevent=ev| |Event; A at if(Oevent.ctrlkey && oevent.keycode== -) - { -Otxt1.value+=otxt2.value+'\ n'; -Otxt2.value="'; - } - }; in }; -</script> to + -<body> the<textarea id="txt1"Rows="Ten"cols=" +"></textarea><br/> *<input id="txt2"Type="text"/> $<input id="BTN1"Type="Button"Value="message"/>Panax Notoginseng</body> -Event Basics (ii) keyboard events