可能重复:
Different forms of $(document).ready
What is the difference between these jQuery ready functions?
以下两个函数有什么区别?:
$(function() { });
和
$(document).ready(function(){});
答案 0 :(得分:0)
.ready是DOM准备就绪后使用的处理函数
.ready()方法通常与属性不兼容。
我会正常使用$(function() {});
。
$(document).ready(function(){});
通常用于匿名函数
以下所有三种语法都是等效的:
$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)