因此,我想获取一个 div 的背景图像的实际大小,并在该站点中搜索我在这个 url 中发现了一些很棒的 JavaScript 代码:http: //jsbin.com/olozu/2/edit。
但是,它似乎在我的网站上不起作用,我不知道为什么,尽管我的代码与上面的代码相同。
这是我的代码(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 高。