我正在使用< head> 内的< script> 执行外部脚本。 / p>
现在,由于脚本在页面加载之前执行,因此我无法访问< body> 等。在文档加载后(HTML已完全下载并在RAM中),我想执行一些JavaScript。在脚本执行时,是否有任何事件可以挂接到页面上?
解决方案这些解决方案将工作:
< body onload = script();>或
document.onload =函数...甚至
window.onload =函数...请注意,最后一种选择是更好的选择,因为它是 ,并且考虑了更多标准。
>I'm executing an external script, using a <script> inside <head>.
Now since the script executes before the page has loaded, I can't access the <body>, among other things. I'd like to execute some JavaScript after the document has been "loaded" (HTML fully downloaded and in-RAM). Are there any events that I can hook onto when my script executes, that will get triggered on page load?
解决方案These solutions will work:
<body onload="script();">or
document.onload = function ...or even
window.onload = function ...Note that the last option is a better way to go since it is unobstrusive and is considered more standard.
更多推荐
页面加载后如何使JavaScript执行?
发布评论