jQuery 文档就绪函数 [英] jQuery document ready function

查看:42
本文介绍了jQuery 文档就绪函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 jQuery 片段的最终结果是否相同?

片段 1:

$(function() { alert('test!'); });

代码段 2:

$(document).ready(function() { alert('test!'); });

换句话说,$(function(){}) 只是 $(document).ready(function() { }); 的简写吗?>

我之所以这么问是因为我们发现使用 jQuery 和 jQuery UI 构建的小应用程序存在一些奇怪的问题.有时,当通过单击按钮执行表单提交操作时,浏览器窗口会冻结.我们仍然可以使用底层浏览器窗口(启动弹出窗口的窗口),直到我们在那里执行一些操作.用户只能通过强制关闭浏览器(显然是 Internet Explorer)来继续.我们怀疑这与 Acrobat PDF 插件有关,但我只是在这里检查所有角度,因为我发现了这个问题 似乎表现出类似的行为.

解决方案

是的,它们是等效的.请参阅此链接以供参考 .ready()

Are the end results of the following jQuery snippets identical?

Snippet 1:

$(function() { alert('test!'); });

Snippet 2:

$(document).ready(function() { alert('test!'); });

In other words, is $(function(){}) just shorthand for $(document).ready(function() { });?

The reason I'm asking is because we're seeing some strange issues with a small application we've built using jQuery and jQuery UI. Occasionally, when performing a form submit action by clicking a button the browser window will just freeze. We can still use the underlying browser window (the one that launches the pop-up) until we perform some actions there. The users can only continue by force closing the browser (Internet Explorer, obviously). We suspect this is related to the Acrobat PDF plug-in, but I'm just checking all the angles here, because I found this issue which seems to exhibit similar behaviour.

解决方案

Yes they're equivalent. See this link for reference .ready()

这篇关于jQuery 文档就绪函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆