g.a.: bilderpositzion

Beitrag lesen

ok, hab jetz das:
"
<html>
<head>
<script>

function beweg(e)
    {
      var keyCode = (e) ? e.which :event.keyCode;

if(keyCode==100){document.getElementById("box").style.left=document.getElementById("box").style.left+1;}
if(keyCode==97){document.getElementById("box").style.left=document.getElementById("box").style.left-1;}
if(keyCode==119){document.getElementById("box").style.top=document.getElementById("box").style.top-1;}
if(keyCode==115){document.getElementById("box").style.top=document.getElementById("box").style.top+1;}
if(keyCode==101){alert("a=" + document.getElementById("box").style.left + ";w=" + document.getElementById("box1").style.top);}

}

document.onkeypress=beweg;
</script>

<body>
diese box lasst sich mit den tasten: [W],[A],[S]und[D] hinundher bewegen.

<style type="text/css">
#box { position:absolute; top:100px; left:100px; width:100; height:100; }
</style>
</head><body>
<div id="box" style="background:red;">ICH BIN DIE BOX</div>
<body>
</html>
"

funktioniert aber nich so ganz. könnt ihr selbst ausprobieren.
warum funktioniert das nich? ich habe keine erklärung gefunden.