If you want an event to work on your
page,you should call it inside the
$(document).ready() function.
Everything inside it will load as soon
as the DOM is loaded and before
the page contents are loaded.
我想在加载页面内容后才能执行JavaScript代码,我该怎么做?
解决方法
使用负载而不是准备好:
$(document).load(function () { // code here });
更新 – 您需要使用$(window).on(‘load’,function(){… since jQuery 1.8.
According to 07001:
Removed deprecated event aliases
.load
,.unload
,and.error
,deprecated since jQuery 1.8,are no
more. Use.on()
to register listeners.07002