Javascript 事件onResize不处理标记img
我有这个:Javascript 事件onResize不处理标记img,javascript,html,css,Javascript,Html,Css,我有这个: <html> <head> <title>Test</title> <script> function onLoad(img) { alert(img.width); alert(img.height); } function clickc() { var a = document
<html>
<head>
<title>Test</title>
<script>
function onLoad(img) {
alert(img.width);
alert(img.height);
}
function clickc() {
var a = document.getElementById("testdiv1");
a.style.display = "inline";
}
function onResize(img) {
alert(img.width);
alert(img.height);
}
</script>
</head>
<body>
<div id="testdiv1" style="display: none;">
<img id="testImg" src="C:\workspaces\hudsonspace28\g6-formcenter-test\bin\com\senior\formcenter\test\file\resources\Tulipas.jpg" onload="onLoad(this);" onresize="onResize(this);"/>
</div>
<button onclick="clickc()"/>
</body>
</html>
我的目标是尽可能获得图像的大小,因为在这种情况下,Chrome/Firefox/IE11在
onLoad
中返回图像的大小,但在IE9/IE10中返回大小0。图像没有resize
事件,为什么会这样?在Chrome或Firefox中,从不调用事件resize
。但在IE9或IE10中,当我将父级div
的样式设置为display:inline
时,会调用它。
<div id="testdiv1" style="display: none;">
<img id="testImg" src="C:\workspaces\hudsonspace28\g6-formcenter-test\bin\com\senior\formcenter\test\file\resources\Tulipas.jpg"/>
</div>
<button onclick="clickc()"/>
<script>
document.getElementById("testImg").addEventListener("load", onLoad, false);
document.getElementById("testImg").addEventListener("resize", onResize, false);
</script>