jQuery中$(fn)和$(document).ready(fn)之间的区别?

时间:2012-09-21 04:58:20

标签: javascript jquery

  

可能重复:
  Different forms of $(document).ready
  What is the difference between these jQuery ready functions?

以下两个函数有什么区别?:

$(function() { });

$(document).ready(function(){});

1 个答案:

答案 0 :(得分:0)

.ready是DOM准备就绪后使用的处理函数 .ready()方法通常与属性不兼容。 我会正常使用$(function() {});

$(document).ready(function(){});通常用于匿名函数

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

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

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