HTML 中的 Javascript 加载 [英] Javascript onload in HTML
问题描述
我想问一个关于Javascript的onload
的问题.
I want to ask a question about the Javascript’s onload
.
我正在编写一个 JSP 页面,代码为 <%@ include file ="body.jsp"
.包含的 body.jsp
包含:
I’m writing a JSP page with the code <%@ include file ="body.jsp"
. The included body.jsp
contains:
<table onload="function()">
这应该加载javascript函数,但它似乎对页面没有任何影响.onload
只能在 body
标签上使用吗?
This should load the javascript function, but it doesn't appear to have any effect on the page. Is onload
only usable on the body
tag?
推荐答案
Onload 只能用于 ,
,
<script>
, <iframe>
标签,因为它告诉你外部资源(图像、脚本、框架)或整个页面(正文)何时被加载
Onload can only be used for <body>
, <img>
, <script>
, <iframe>
tags, because it tells you when an external resource (image, script, frame) or the whole page (body) has been loaded
由于 HTML5 这些也可以触发 load 事件:,
,
,
尽管如此,对这些的支持仍然是成功的或失败的(例如旧的 Android 浏览器)
Since HTML5 these can also fire a load event: <link>
, <style>
, <input type=image>
, <object>
Support for these can still be a hit or miss though (e.g. older Android browsers)
这篇关于HTML 中的 Javascript 加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!