當我在樣式表中設置屬性時,我無法訪問JavaScript函數中一個圖像元素的left
屬性,但是當我在圖像標籤上使用內聯樣式時,它工作正常。爲什麼我無法在JavaScript函數中訪問此CSS屬性?
這裏是我的代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function moveObjRight(obj) {
var a = document.getElementById(obj);
alert(a.style.left)
}
</script>
<style type="text/css">
#AS
{
top: 141px;
left: 118px;
position: absolute;
height: 25px;
width: 25px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<img alt="asd" src="pic 3-4.jpg" id="AS" />
<input type="button" value="Button" onclick="javascript:moveObjRight('AS');" />
</div>
</form>
</body>
</html>
它是* [模因(http://meta.stackexchange.com/questions/19478/the-many-memes-of-meta/19492#19492) *。 – 2012-11-21 18:07:07