在 jQuery 站点上,对 $(callback)
的描述是它的行为与 $(document).ready(function)
相同,但示例显示两种语法之间的一些差异。所以我想知道,有谁知道两者之间的确切区别是什么?
最佳答案
没有区别,文档也没有显示任何区别:
All three of the following syntaxes are equivalent:
- $(document).ready(handler)
- $().ready(handler) (this is not recommended)
- $(handler)
直接来自:http://api.jquery.com/ready/
我认为您对显示 jQuery(function($){ ... });
的示例感到困惑
这只是调用 $(handler)
的一种方式,没有 $
冲突。
IE.
// Here `$` is used by another library
jQuery(function($){
// Here `$` refers to jQuery
});
关于javascript - $(callback) 和 $(document).ready(function) 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7068916/