我很困惑什么是真正的意思
(function ($){})(jQuery)
//in plugin和
$(function (){})
//in page.请在这一点上给我澄清一下。
发布于 2012-09-11 16:04:07
这一点:
(function ($){})(jQuery) 使用作为参数传入的JQuery对象,对定义的函数执行...is操作,然后立即调用。$是对JQuery的引用,您可以在函数内部使用它。它等同于:
var myFunc = function ($){};
myFunc(jQuery);这一点:
$(function (){})...is一个对JQuery的调用,传入一个在文档加载完成后应该执行的函数。
发布于 2012-09-11 15:14:21
$(function(){}); === $(document).ready(function(){});. 以上两个都是相同的。
其中,as,(function($){ .... })(jQuery);是编写插件的结构。
发布于 2012-09-11 15:25:51
这两个不是下面的same.The将会清楚地解释所有的事情,
(function($){
/* code here runs instantly*/
$('document').ready(function(){ // this function is exactly the same as the one below
/* code here runs when dom is ready */
});
$(function(){ // this function is exactly the same as the one above.
/* code here runs when dom is ready */
}
)(jQuery); // jQuery is a parameter of function($) {}参考:http://forum.jquery.com/topic/what-s-the-difference-between-function-code-jquery-and-document-ready-function-code
https://stackoverflow.com/questions/12364496
复制相似问题