简体   繁体   English

我可以在此示例中立即调用函数,而不用匿名函数将其包装吗?

[英]Can I call my function in this example immediately instead of wrap it by anonymous function?

I don't know how to pass $(this) in direct call 我不知道如何直接拨打$(this)

var parentLI = $("#nav .parent");

parentLI.hoverIntent(function() {
    showUL($(this));
}, function() {
    hideUL($(this));
});

You can give the functions by reference: 您可以通过引用给出功能:

parentLI.hoverIntent(showUL, hideUL);

Then in those functions you can refer to the element which raised the event by the this keyword: 然后,在这些函数中,您可以通过this关键字引用引发事件的元素:

function showUL() {
   var $el = $(this);
   // do something with $el...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么他们用匿名函数包装代码并立即调用它,而不是简单地执行相同的代码? - Why they wrap code with anonymous function and call it immediately instead simple executing same code? 如何在该匿名javascript中调用该函数? (TinyMce示例) - How can i call that function inside that anonymous javascript? (TinyMce example) 匿名函数调用的MDN示例 - MDN example of Call on an anonymous function 我可以稍后再调用一个匿名函数吗 - Can i call an anonymous function later on 为什么我必须在匿名函数中包含Javascript函数调用才能立即调用它? - Why do I have to enclose a Javascript function call in an anonymous function for it to not be called immediately? 如何在javascript匿名函数中调用类释放函数 - How can I call the class slibing function in javascript anonymous function 如何将其包装为一个函数,而不是重复九次? - How can i wrap this as one function instead of repeating it nine times? 为什么将一个函数引用包装成一个匿名函数可以更正'this'指向? - Why wrap a function reference into an anonymous function can correct 'this' point to? 如何在JavaScript中从内部调用匿名函数? - How can I call an anonymous function from inside itself in JavaScript? 我可以通过触发一些东西在jQuery中调用这个匿名函数吗? - Can I call this anonymous function in jQuery by triggering something?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM