哪些HTML5元素具有onload/“加载事件"? [英] Which HTML5 elements have onload/"load event"?

查看:59
本文介绍了哪些HTML5元素具有onload/“加载事件"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mozilla的MDN 通知加载具有此存根的事件:

当资源及其从属资源时,将触发load事件完成加载.

The load event is fired when a resource and its dependent resources have finished loading.

并链接到

标准1 ,它通知

受信任的目标:窗口,文档,元素

Trusted Targets: Window, Document, Element

因此,相关的 onload 处理程序和 load 事件似乎设计为可与Element一起使用.看来这样的元素是< img> ,指示该元素的加载.

It seems that the related onload handler, and the load event is hence designed to work with Element. It seems such an element is <img> to indicate the loading of this.

请注意,现在我在窗口/文档上的 load 事件还指示其所包含的元素的加载状态,但有些

Please note that I now that the load event on the window/document indicates also the load state of its contained Elements but some Element can

a)更改其 src / href 属性(< img> < script> < link> ,....)b)或其内联内容(< style> < script> )

a) change their src/href property (<img>, <script>, <link>,....) b) or their inline content (<style>, <script>)

.

有了这个问题,我想知道哪些元素支持 load 事件 onload .Handler".

With this question I seek help knowing "which Elements support the load Event, onload.Handler.

我在Chromium和Firefox中对此进行了测试,并且似乎支持< style> < script>

I tested this in Chromium and Firefox and it seems it is supported in <style>, <script>

var styleElement = document.createElement("style");
styleElement.onload = function() { 
    console.log("styleElement onload called");
};
document.head.appendChild(styleElement);
// output: "styleElement onload called";

但是我不确定所发现的行为是否确实在标准中指定的任何地方?

but I am unsure if the discovered behavior is actually anywhere specified in the stanards?

推荐答案

支持的HTML标记如下:< body>,< frame>,< iframe>,< img>,< input type ="image"> ;,< link>,< script>,< style>

Supported HTML tags are as follows : <body>, <frame>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>

我在< h1>上进行了测试标签,但没有成功

I tested it on <h1> tag but it didn't work out

<h1 onload="myFunction()">Hello World!</h1>;

有关更多详细信息,请访问 W3学校

For more details, visit W3 schools

这篇关于哪些HTML5元素具有onload/“加载事件"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆