<body onkeydown="move(event.keyCode)"></body>
<script>
function move(code){
if(code==37)
alert("左");
if(code==38)
alert("上");
if(code==39)
alert("右");
if(code==40)
alert("下");
}
</script>

解决方案 »

  1.   

    js用上下左右光标及小键盘上的上下左右控制一个图像上下左右走动的程式
    <HEAD> 
    <TITLE> New Document </TITLE> 
    <div id=m style="display:none">请等待</div> 
    </HEAD> 
    <body onkeydown='onkeydowm()'> 
    <img src=http://www.hycenter.net/copyrights/hybbs/image/logo.gifstyle="position:absolute" id=demo> 
    <script> 
    function document.onkeydown(){ 
    // +----------------------------------------------------+ 
    // | 用上下左右光标及小键盘上的上下左右控制一个图像 
    // | 上下左右走动的程式 
    // +----------------------------------------------------+ 
    var kc=window.event.keyCode-101;//初始化变量kc 
    if (window.event.keyCode==39)demo.style.pixelLeft+=30;//如果是光标右键图像右移30个像素 
    if (window.event.keyCode==40)demo.style.pixelTop+=30;//如果是光标下键图像下移30个像素 
    if (window.event.keyCode==37)demo.style.pixelLeft-=30;//如果是光标左键图像左移30个像素 
    if (window.event.keyCode==38)demo.style.pixelTop-=30;//如果是光标上键图像上移30个像素 
    if(Math.abs(kc)==1)demo.style.pixelLeft+=kc*30;//如果是小键盘光标左右键图像左右移30个像素 
    if(Math.abs(kc)==3)demo.style.pixelTop-=kc*10;//如果是小键盘光标上下键图像上下移30个像素 

    </script> 
    </body> 
    </HTML>
      

  2.   

    不好意思,提问错了。应该还要加上要在 mozilla 中也可以。