所以,我想获取一个div背景图像的实际大小,在网站上搜索后,我在这个链接中找到了一些很棒的JavaScript代码:http://jsbin.com/olozu/2/edit。
然而,它似乎在我的网站上无法工作,尽管我的代码与上述代码完全相同。
以下是我的代码(JS Bin)
HTML:
如果您点击左边的图片,它将显示0宽度0高度。
然而,它似乎在我的网站上无法工作,尽管我的代码与上述代码完全相同。
以下是我的代码(JS Bin)
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body onclick="picture()">
<img id="topicinfo" src="http://pierre.chachatelier.fr/programmation/images/mozodojo-original-image.jpg"><
</body>
</html>
JavaScript:
function picture()
{
var a=document.getElementById("topicinfo").height;
alert(a);
}
如果您点击左边的图片,它将显示0宽度0高度。
imageSrc
似乎为空。你的代码与他们的代码不同,背景图片是内联声明的。请参见:http://jsbin.com/uzejah/7/edit - ahren