日期:2014-05-16  浏览次数:20344 次

为什么我用getElementById得到的对象属性为空呢?
HTML code

<body>

<img src="../javascript/images/icon2.gif" id="img2"  />
<script type="text/javascript">
    var ml = document.getElementById("img2");
    alert(ml.style.height);
</script>

</body>


弹出对话框 是空的,,,让我很郁闷啊!求解释啊!

------解决方案--------------------
HTML code
<body>

<img src="../javascript/images/icon2.gif" id="img2" style="height:10px"  />
<script type="text/javascript">
    var ml = document.getElementById("img2");
    alert(ml.style.height);
</script>

</body>