gpt4 book ai didi

jquery - jQuery(function($) 和 $(function() 之间有什么区别?

转载 作者:行者123 更新时间:2023-12-01 03:19:31 25 4
gpt4 key购买 nike

我正在查看一段我没有编写的代码,其中包含:

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.

通常我会编写代码在 $(document).ready({ ... }); 内部运行例如:

$(document).ready({

.click(function() {
var $this = $(this);
var thisID = $this.attr('id');
//hide all visiable detail pages
resetpage($('.item-detail:visible'));
... etc.

}
});

这两种编写函数的方式有什么区别(如果有),或者我可以互换使用它们吗?

最佳答案

您可以互换使用它们。 $jQuery 的简写,$(function(){..})$(document).ready 的简写(函数(){});

有时人们使用 jQuery(function($){ }); 因为 $ 符号被另一个库使用,或者与 PHP 冲突> 在服务器上。

关于jquery - jQuery(function($) 和 $(function() 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11461478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com