【发布时间】:2011-12-07 17:32:12
【问题描述】:
我有这样的代码行:
$(this).parent().parent().children().each(function(){
// do something
});
效果很好。但我需要多次运行这些行。 所以我创建了一个函数并将 $(this) 参数传递给一个函数:
myFunc( $(this) );
function myFunc(thisObj) {
thisObj.parent().parent().children().each(function(){
// do something
});
}
但是这样一来,就不行了。
【问题讨论】:
-
如果你使用“this”而不是“$(this)”作为参数呢?
-
您编写的代码没有任何问题,所以我建议这是其他地方的错误。 “它没有用”是什么意思?
-
我用过“this”,但它也不起作用。当我在 Firebug 中看到 $this 和 thisObj 时,它会显示: {$this = input.focus} 但是 {thisObj = [input.focus]} ... 有什么区别吗?
-
@Natasha 你解决了这个问题吗?
标签: jquery this parameter-passing