它们之间的区别是什么
$(function(){
});
和
$(document).ready(function() {
});
发布于 2010-04-18 23:39:48
Nothing whatsoever.
此函数的行为类似于$(document).ready(),因为它应该用于包装其他$()
可以在source code中看到这一点
rootjQuery = jQuery(document);
...
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
发布于 2011-03-04 02:19:47
} else if (jQuery.isFunction(selector)) {
return rootjQuery.ready(selector);
}
从source
调用$(document).ready(selector)
可以节省一些if语句。
尽管jQuery确实在内部缓存了$(document)
,但这可能会使$(f)
更快。
Benchmarked
发布于 2011-03-04 02:17:39
两者是等价的,第一个是速记形式。
https://stackoverflow.com/questions/2662778
复制相似问题