JQuery 将其传递给函数
我需要将 this
发送到 capIn() 和 capOut() 函数,以便我可以定位正确的 .slide 的子 div。如何将 this
传递给函数。 this
将是悬停的内容。
$(".slide").hover(function(){capIn();capOut();});
I need to send this
to the capIn() and capOut() functions so that I can target the children divs of the correct .slide. How do I pass this
to a function. this
would be what is hovered.
$(".slide").hover(function(){capIn();capOut();});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看函数名称
capIn
和capOut
可以看出它们是两种不同的行为。我相信您对mouseenter
和mouseleave
事件有两种不同的行为。hover
方法可以采用 2 种方法,一种用于mouseenter
,另一种用于mouseleave
。您可以尝试这个您可以在
capIn
和capOut
中使用this
它将指向您悬停的.slide
元素在。Looking at the function names
capIn
andcapOut
it makes sense that they are 2 different behaviors. I believe you have 2 different behaviors onmouseenter
andmouseleave
events.hover
method can take 2 methods, one formouseenter
and another formouseleave
. You can try thisYou can use
this
insidecapIn
andcapOut
it will point to.slide
element which you hovered on.请参阅此处:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function /apply
更新:
如果
capIn
用于mouseenter
并且capOut
用于mouseleave
,那么:ShankarSangoli
的解决方案比较简洁,但是如果除了this
之外还需要传递任何参数,那么:capIn.apply(this,arguments)。
See here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply
UPDATE:
If
capIn
is formouseenter
andcapOut
is formouseleave
, then:ShankarSangoli
's solution is more succinct, but if any arguments need to be passed in addition tothis
, then:capIn.apply(this, arguments)
can be used.这对我有用:
This works for me: