jQuery的ready()方法的快捷方式 [英] Shortcuts for jQuery's ready() method
问题描述
我已经看到了ready()方法的一些快捷方式,并且想知道哪个首先发生,因为我的测试结果使我感到困惑.
I have seen some shortcuts for the ready() method and would like to know which actually happens first, because my test results confuse me..
$(document).ready(function(){
alert("document ready");
});
$(window).load(function(){
alert("window ready");
});
(function($){
alert("self invoke");
})(jQuery);
在此先进行自我调用,然后是文档,然后是窗口. 自我调用技术是否被视为 ready()方法?
Here self invoke happens first, then document, then window. Is the self invoke technique considered a ready() method?
推荐答案
第三个选项不是.ready()
(或与jQuery有关的快捷方式)的快捷方式,自我调用立即运行 (尽快)就像代码中显示的一样),这可能是您正在考虑的快捷方式:
The third option is not a shortcut for .ready()
(or jQuery related really), the self invoke runs immediately (as soon as it appears in the code), this is probably the shortcut you're thinking of though:
$(function(){
alert("I'm a ready shortcut");
});
将函数传递到 $(func)
是$(document).ready(func);
的快捷方式. 不冲突版本如下所示:
Passing a function into $(func)
is a shortcut for $(document).ready(func);
. The no-conflict version would look like this:
jQuery(function($) {
//$ is jQuery
});
这篇关于jQuery的ready()方法的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!