我正在做一個關於定位圖像的練習,從一本書。它說,使用DOM,即圖像的位置,頂部和左側值,我們可以使用JavaScript在瀏覽器窗口中移動圖像。圖片在瀏覽器中沒有被移位
事情是我有圖像得到顯示,但是當我輸入座標時,它不會移位到它的新值。請如果有人能告訴我我要去哪裏錯?
這裏是HTML文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="newjavascript.js">
</script>
</head>
<body>
<form action="">
<p>
Xcordinate : <input type="text" id="xCod" /><br/>
Ycordinate : <input type="text" id="yCOd" /><br/>
</p>
<br/>
<input type="submit" value="Set the Coordinates" onclick = "moveIt('image', document.getElementById('xCod').value,
document.getElementById('yCod').value)" />
</form>
<div id="image" style="position: absolute; left:0; top:200px" >
<img src="testing.jpg" alt="Picture Cannot be displayed" />
</div>
</body>
</html>
和JavaScript文件
function moveIt (movee, newTop, newLeft){
dom = document.getElementById(movee).style;
dom.top=newTop+"px";
dom.left=newLeft+"px";
}
我有默認瀏覽器,谷歌瀏覽器
看起來沒問題乍一看。按下「Ctrl + Shift + J」並點擊「控制檯」查看JavaScript錯誤 – 2010-11-23 23:48:19