$(callback)和$(document).ready(function)之间的区别? [英] Difference between $(callback) and $(document).ready(function)?

查看:137
本文介绍了$(callback)和$(document).ready(function)之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery网站上, $(callback)的描述是它的行为与 $(document).ready(function) 但是示例显示了两种语法之间的一些差异。所以我想知道,有没有人知道两者之间的区别是什么?

解决方案没有区别,不显示任何差异:


以下所有三种语法都是等效的:




  • $(document).ready(handler)

  • $()。ready(handler) $ b
  • $(处理程序)


直接从:http://api.jquery.com/ready/



我认为你对示例 jQuery(function($){...});
这只是一种调用 $ / code>,没有 $ 冲突。



IE。

  //这里`$`被另一个库使用
jQuery(function($){
//这里`$` jQuery
});


On the jQuery site, the description for $(callback) was that it behaves the same as $(document).ready(function) but then the examples showed some differences between the two syntaxes. So I was wondering, does anyone know exactly what the differences between the two are?

解决方案

There are no differences, and the docs don't show any difference:

All three of the following syntaxes are equivalent:

  • $(document).ready(handler)
  • $().ready(handler) (this is not recommended)
  • $(handler)

Straight from: http://api.jquery.com/ready/

I think you are confused by the example showing jQuery(function($){ ... }); Which is just a way of calling $(handler), with no $ conflict.

IE.

// Here `$` is used by another library
jQuery(function($){
    // Here `$` refers to jQuery
});

这篇关于$(callback)和$(document).ready(function)之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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