使用 jQuery 在悬停时显示隐藏类
我对 jQuery 比较陌生,我希望能够在鼠标悬停时显示菜单。
这是 HTML 内容:
<td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/>
<span class="comment_actions"> Approve | Delete | Spam | Edit</span>
</td>
然后是 jQuery 代码:
$("comment_div").hover(
function() { $(".comment_actions").show(); },
function() { $(".comment_actions").hide(); }
);
除了我拉出多个注释之外,这都有效,并且无论悬停什么“注释”,这只都会在第一个 div 上显示菜单。我想让菜单仅显示当前悬停在其上的评论。我想我需要使用“$this”来完成这项工作,但我不知道如何做。
I am relatively new to jQuery, and I would like to be able to show a menu on mouseover.
Here is the HTML content:
<td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/>
<span class="comment_actions"> Approve | Delete | Spam | Edit</span>
</td>
Then the jQuery code:
$("comment_div").hover(
function() { $(".comment_actions").show(); },
function() { $(".comment_actions").hide(); }
);
This works except for I'm pulling multiple comments out and this only will show the menu on the first div no matter what "comment" is hovered. I would like to have the menu show only for the comment that is currently being hovered over. I think I need to use "$this" to make this work, but I am not sure how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我没看错的话,格式应该是-
If I'm reading that correctly, the format should be-
这样的事情对我有用:
但是,您将面临的问题是将鼠标悬停在具有
display: none; 的 div 上。设置。您可能需要考虑将其包装在对鼠标敏感的东西中,然后显示/隐藏子项。
Something like this works for me:
However, the issue you'll face is hover actions over a div that has
display: none; set
. You might want to consider wrapping it in something that's mouse sensitive, and then displaying/hiding children instead.