Javascript高手来

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:43:16
<div name="Layer7" id="Layer7" style="position:absolute; left:185px; top:265px; width:2px; height:2px; z-index:7"><img src="images/tm.gif" name="photo3" width="140" height="30" id="photo3"></div>

如何用Javascript取到 img 的 width的value
谢谢楼下的回答可这样还是取不到值的你可以试下!

<img src="images/tm.gif" width="140" height="30" id="photo3">
<script type="text/javascript">
var getObject=document.getElementById("photo3");
alert(getObject.width);//方法1
alert(getObject.getAttribute("width"));//方法2 DOM编程标准方法
</script>

楼主代码那么多!既然要取图片的宽值,而且又给图片定义了ID号,不用外边DIV了。

(Val)=photo3.width
修改 :可以的,看实例
<html>
<script>
function cc(){
alert(t2.width);
}
</script>
<body>
<img id=t2 src="aaa" width=500></img>
<a href=# onclick=cc()>aa</a>
</body>
</html>

document.getElementById('photo3').width.value