在JQuery中,我们如何将整个$(this)传递给函数?可能?
1
A
回答
5
嗯,这取决于你逝去的是什么,但你只是尝试了以下内容:
function do_something_cool(jquery_link_object) {
/* I do something awesome! */
}
$('a.my_link_class').click(function() {
do_something_cool($(this));
});
这将通过单击链接到do_something_cool
方法。
0
$(this)
元素暴露在大多数jQuery事件操作中。你可以添加一个函数参数给你的jQuery处理程序。
$("a.someClass").live("click", function(e) {
// $(this) is a reference to the same <a> element.
var link = $(this);
doSomethingToLink(link);
});
+0
完全没有关系,而且最重要的是,错误:'e'是**不是**对引用的引用,它是** Event **对象。 – 2010-03-12 14:33:11
+0
对不起,你是对的。修正了我的例子 – 2010-03-12 15:19:27
0
你的问题不是很具体,但也许你想是这样的:
$("a.myLinkClass").click(
function(){
$(this).addClass('myClickedLinkClass'); // 'this' refers to the anchor element that was clicked
}
);
相关问题
- 1. fancybox - 将'this'传递给onClosed函数
- 2. 如何将$(this)传递给函数?
- 3. jquery将$(this)传递给其他函数
- 4. jQuery - 如何将'this'传递给函数?
- 5. 如何将$(this)传递给函数?
- 6. 将$(this)传递给jQuery .hover()函数
- 7. 将'this'引用传递给Backbone函数
- 8. 将'this'传递给axios promise'then'?
- 9. jQuery:将$ this与其他参数一起传递给函数
- 10. 将$(this)传递给jQuery中的回调函数?
- 11. 在鼠标悬停中将$(this)传递给setTimeout函数
- 12. 如何将$(this)引用传递给回调函数?
- 13. 将“this”传递给基础构造函数
- 14. 如何将对'this'的引用传递给函数?
- 15. 将当前聚合物对象(this)传递给回调函数
- 16. 将$(this)选择器传递给嵌套函数
- 17. 如何将“this”指针传递给全局函数
- 18. 将“this”传递给函数的等价物是什么?
- 19. 将self.property传递给函数
- 20. 将struct传递给函数
- 21. 将javascript传递给函数
- 22. 将函数传递给#selector
- 23. 将值传递给函数
- 24. 将函数传递给Backbone.View.extend
- 25. 从函数传递$(this)到函数
- 26. 将函数传递给jQuery .ready()函数
- 27. 将函数传递给函数SML
- 28. 将此函数传递给函数
- 29. 将结构函数传递给函数
- 30. 将函数传递给构造函数
是的,你可以在Javascript中调用一个函数来传递一个对象作为参数。为什么这是一个问题? – 2010-03-12 14:30:27