Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 事件onResize不处理标记img_Javascript_Html_Css - Fatal编程技术网

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>