[英]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.