【发布时间】:2012-07-12 18:32:26
【问题描述】:
我正在查看一段我没有编写的代码,其中包含:
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.
}
});
这两种编写函数的方式有什么区别(如果有的话),或者我可以互换使用它们吗?
【问题讨论】:
-
更多关于domready方法的信息:stackoverflow.com/questions/10753306/…