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

如何取这图片的高?
我有一代码,我想用jquery取2012-313.gif图片的高度,怎么取??
HTML code


<div id='new1' style='margin:auto; display:none; width:960px; top:0px; height:0px;overflow:hidden;'><img src='/images/2012-313.gif' width='960' height='381' border='0' usemap='#Map' id='img1'/><map name='Map' id='Map' > <area  shape='rect' coords='900,5,954,30'  onclick='javascript:$('#newyear').animate({height:0},{duration:'slow'})' /> <area shape='rect' coords='44,7,888,369' target='_blank' href='/years.html' /></map></div> <div id='yearsNotice' style='margin:auto; display:none; width:960px;'><a target='_blank'  href='/year1.html'><img src='/images/2012-313-1.gif' width='960' height='32' border='0' /></a></div>




------解决方案--------------------
$('#图片ID').height()
建议这种问题查一下帮助 文档
------解决方案--------------------
$('img1').getAttribute('height')
------解决方案--------------------
探讨

$('#图片ID').height()
为零,取不到的

------解决方案--------------------
$('#img1').css('height')
------解决方案--------------------
给你一个原生的方法
var getHeight = function(p, img){
var pStyle = p.style, h;
pStyle.visibility = 'hidden';
pStyle.display = 'block';
h = img.offsetHeight;
pStyle.visibility = '';
pStyle.display = '';
return h;
}
getHeight(document.getElementById('new1'),document.getElementById('img1'))