你知道哪个更好,为什么?
第一个;
$(document).ready(function() {
// your code
});
第二个 :
$(function() {
// your code
});
你知道哪个更好,为什么?
第一个;
$(document).ready(function() {
// your code
});
第二个 :
$(function() {
// your code
});
没关系。我更喜欢第二种情况,因为它更容易打字。
这就是函数在内部所做的。
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
它们是等价的。这取决于您想要的详细程度或简洁程度。
以下所有三种语法都是等效的:
$(document).ready(handler)
$().ready(handler) // (this is not recommended)
$(handler)
两者都是相同的参考:http ://api.jquery.com/ready/