$(document).ready() 完成后如何触发某些内容?
有没有办法让您的函数作为 $(document).ready()
队列中的最后一个函数被调用,或者有没有办法在完成后触发事件?
我主要想看看 $(document).ready() 是否触发了某些内容,如果没有,则在之后触发它。如果我将此代码放入准备好的文档中,则不能保证它会最后执行,因此可能会导致多次检查。
Is there a way to have your function be called as the LAST in the $(document).ready()
queue or, is there a way to trigger an event once this has completed?
I want to essentially see if something was fired by $(document).ready()
and, if not, fire it after wards. If I put this code into document ready then there is no guarantee it will execute last so could result in multiple checks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在函数被触发时设置一个全局变量,并在再次运行之前进行检查:
例如,
这并不能保证您的函数将最后运行,但满足我认为您的真正要求,即该函数不会在一次运行多次要求。
You can set a global variable when your function is fired, and check that before running it again:
E.g.,
This does not guarantee your function will run last, but satisfies what I think is your real requirement that the function not run multiple times in one request.
在代码末尾添加另一个
$(document).ready()
块。 jQuery 按照它看到的顺序执行它们,因此,如果您在代码末尾放置另一个块,则应在另一个块完成后调用它。Add another
$(document).ready()
block to the end of your code. jQuery executes them in the order it sees them, so if you put another block at the end of the code, it should be called after the other finishes.这听起来像是readyX插件的完美用例: http://plugins.jquery.com/project/readyx
该插件为应该最后发生的就绪事件提供了一个队列。
This sounds like the perfect use case for the readyX plugin: http://plugins.jquery.com/project/readyx
The plugin provides a queue for ready events that should happen last.