何时在jQuery中使用$(document).ready()以及何时使用$(window).load()?
$(窗口).load()
当您希望其中的代码仅在整个页面准备好后才运行(不仅是DOM),请使用$(window).load()。页面完全加载后执行,包括框架,对象和图像
注意:该load()
方法在jQuery1.8版中已弃用。在3.0版中将其完全删除。要查看其工作原理,请在3.0之前添加CDN的jQuery版本。
$(document).ready()
当页面DOM准备执行JavaScript代码后,如果希望其中的代码运行,请使用$(document).ready()方法。