jQuery Ready() 的正确使用
您希望使用 jquery.ready() 的示例是什么?在 DOM 完全构建之前,您希望代码什么时候运行?
编辑: 对不起!我不是这个意思!我的意思恰恰相反! read() 确实使代码在 DOM 构建完成后运行,而这通常正是您想要的。但我刚刚了解了 delegate() 函数,我用它来调用一个函数,然后通过 ajax 添加到 DOM 中。为此,我没有使用ready(),只是使用delegate(),我试图找出原因......我对造成的混乱感到非常抱歉。
What is an example of a time where you would want to use jquery.ready()
? When would you want the code to run before the DOM is fully constructed?
EDIT:
Sorry! That's not what I meant! I meant the opposite! ready() indeed makes the code run after the DOM is constructed and quite often this is what you want. But I just learned about the function delegate() which I used to make a function be called on things that were later added into the DOM via ajax. For this I did not use ready(), just delegate() and I was trying to figure out why... I am very sorry for the confusion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议阅读
ready
事件的文档:http://api.jquery.com /准备好/I recommend reading the documentation for the
ready
event: http://api.jquery.com/ready/实际上完全相反。
$.ready()
在 DOM 加载之后运行,任何普通脚本都在之前运行。The complete opposite actually.
$.ready()
runs after the DOM is loaded, any normal script runs before.每当需要与 DOM 元素交互时,就可以使用
$.ready()
例如操作/动画/添加/删除/替换它们。请注意但是,您不能使用
$.ready()
处理图像或框架,除非它们已完全加载,这通常是通过使用onload
完成的> 事件代替。实际上,您在 DOM 完全加载后使用
$.ready()
。您可以在此处阅读完整文档:
You use
$.ready()
whenever you need to interact with DOM elements for example manipulating/animating/adding/deleting/replacing them.Note however that you can not use
$.ready()
to work with images or frames unless they have fully loaded which is usually done by usingonload
event instead.Actually you use
$.ready()
AFTER the DOM has fully loaded.You can read thorough documentation here: