jQuery(函数($)和$(函数())有什么区别? [英] what is the difference between jQuery(function($) and $(function()?
问题描述
jQuery(function($){
$ b $('#interaction')。find('。item')。hover(function(){
var $ this = $(this);
$ this。 addClass('hover');
},
function(){
var $ this = $(this);
$ this.removeClass('hover');
$ b .click(function(){
var $ this = $(this);
var thisID = $ this.attr('id');
/ /隐藏所有可见的详细页面
resetpage($('。item-detail:visible'));
...等等
通常我会写代码在$(document).ready({...})内部运行;例如:
$(document).ready({
.click(function(){
var $ this = $ (this);
var thisID = $ this.attr('id');
//隐藏所有可见的详细页面
resetpage($('。item-detail:visible')) ;
...等等
}
});
这两种写作方式有什么不同(如果有的话)函数还是可以互换使用的?
您可以互换使用它们。 $
简写为 jQuery
和 $(function(){..})
是 $(document).ready(function(){});
有时候人们使用 jQuery(function($){});
因为 $
符号被另一个库使用,或与服务器上的 PHP
冲突。
I'm looking at a piece of code I did not write which contains:
jQuery(function($) {
$('#interaction').find('.item').hover(function() {
var $this = $(this);
$this.addClass('hover');
},
function() {
var $this = $(this);
$this.removeClass('hover');
})
.click(function() {
var $this = $(this);
var thisID = $this.attr('id');
//hide all visiable detail pages
resetpage($('.item-detail:visible'));
... etc.
Normally I would write my code to run inside of $(document).ready({ ... }); for example:
$(document).ready({
.click(function() {
var $this = $(this);
var thisID = $this.attr('id');
//hide all visiable detail pages
resetpage($('.item-detail:visible'));
... etc.
}
});
What is the difference (if any) between these two ways of writing the function or can I use them interchangeably?
You can use them interchangeably. $
is shorthand for jQuery
, and $(function(){..})
is shorthand for $(document).ready(function(){ });
Sometimes people use jQuery(function($){ });
because the $
symbol is used by another library, or conflicts with PHP
on the server.
这篇关于jQuery(函数($)和$(函数())有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!