HTML5图像事件可供开发人员使用

时间:2014-11-19 14:57:24

标签: javascript html5 image javascript-events

我创建了一个HTML5 Web App。

我使用图像控件。

当分配图像src时,我设置了一个局部变量= 1 当图像加载完毕后,我将其设置为0。

如果变量= 0且我的服务器上有另一张图像,我会重复这个过程。

如果引发了img.onerror,我将局部变量设置为0

我注意到,如果我的手机失去了互联网连接,然后将其取回,那么本地变量就会被卡住了#39;在1上,img.src永远不会更新。这不会一直发生。

我猜测img.onload或img.onerror都没有被提出。所以我的问题是img控件引发的其他事件是否可以将处理程序放入?

代码:

我的JS功能由signalR通知我的服务器上有可用的图像。

if (ImageIsLoaded1.Status = 0) {
    var d = new Date();
    var n = d.getTime();
    ImageIsLoaded1.Status = 1;                   
    staticImgArray.src = './NewFrame.ashx?a=' + n
}

staticImgArray.onload = function () { ImageIsLoaded1.Status = 0; };
staticImgArray.onerror = function () { ImageIsLoaded1.Status = 0; };

1 个答案:

答案 0 :(得分:2)

根据官方HTML5 specification,以下是所有可能的global event handlers的IDL定义。作为元素的image元素应该支持所有这些处理程序。

interface GlobalEventHandlers {
       attribute EventHandler onabort;
       attribute EventHandler onblur;
       attribute EventHandler oncancel;
       attribute EventHandler oncanplay;
       attribute EventHandler oncanplaythrough;
       attribute EventHandler onchange;
       attribute EventHandler onclick;
       attribute EventHandler oncuechange;
       attribute EventHandler ondblclick;
       attribute EventHandler ondurationchange;
       attribute EventHandler onemptied;
       attribute EventHandler onended;
       attribute OnErrorEventHandler onerror;
       attribute EventHandler onfocus;
       attribute EventHandler oninput;
       attribute EventHandler oninvalid;
       attribute EventHandler onkeydown;
       attribute EventHandler onkeypress;
       attribute EventHandler onkeyup;
       attribute EventHandler onload;
       attribute EventHandler onloadeddata;
       attribute EventHandler onloadedmetadata;
       attribute EventHandler onloadstart;
       attribute EventHandler onmousedown;
       attribute EventHandler onmouseenter;
       attribute EventHandler onmouseleave;
       attribute EventHandler onmousemove;
       attribute EventHandler onmouseout;
       attribute EventHandler onmouseover;
       attribute EventHandler onmouseup;
       attribute EventHandler onmousewheel;
       attribute EventHandler onpause;
       attribute EventHandler onplay;
       attribute EventHandler onplaying;
       attribute EventHandler onprogress;
       attribute EventHandler onratechange;
       attribute EventHandler onreset;
       attribute EventHandler onresize;
       attribute EventHandler onscroll;
       attribute EventHandler onseeked;
       attribute EventHandler onseeking;
       attribute EventHandler onselect;
       attribute EventHandler onshow;
       attribute EventHandler onstalled;
       attribute EventHandler onsubmit;
       attribute EventHandler onsuspend;
       attribute EventHandler ontimeupdate;
       attribute EventHandler ontoggle;
       attribute EventHandler onvolumechange;
       attribute EventHandler onwaiting;
};