var h=document.getElementById("tp").getAttribute("height");
document.write(h);
因为height不是img的属性,得用.style.height获取
<html> <head> <title></title> <meta charset="utf-8"> </head> <body> <div> <img id="pic" style="height:500px" src="555.jpg"> </div> <script> var ann = document.getElementById("pic"); alert(ann.style.height); </script> </body> </html>
这样就可以得到height的值了