不引人注目的JavaScript加载功能 [英] Unobtrusive JavaScript onload function
问题描述
为什么不引人注目的JavaScript技术需要使用onload函数?我毫不客气的JavaScript代码是否可以在onload函数之外工作?
Why does the unobtrusive JavaScript technique require the use of an onload function? Would my unobtrusive JavaScript code work outside of an onload function?
推荐答案
任何函数之外的全局Javascript都会在解释后立即执行.如果只希望在完全评估DOM之后才运行JS,则使用onload
事件.
Global Javascript outside of any function will execute immediately as it's interpreted. onload
event is used when you want your JS to run only after the DOM is fully evaluated.
使用onload
与DOM合作和/或延迟执行,直到向用户显示该页面为止.
Use onload
to work with the DOM and/or to delay execution until the page is shown to the user.
由于load事件是一个标准事件,因此它与不引人注目的Java脚本的概念并不矛盾.
Since the load event is a standard, it's not incompatible with the concept of unobtrusive Javascript.
这篇关于不引人注目的JavaScript加载功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!