使用jQuery在鼠标悬停时显示隐藏类 [英] Show hide class on hover using jQuery
本文介绍了使用jQuery在鼠标悬停时显示隐藏类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jQuery的新手,我希望能够在鼠标悬停时显示一个菜单。
I am relatively new to jQuery, and I would like to be able to show a menu on mouseover.
以下是HTML内容:
<td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/>
<span class="comment_actions"> Approve | Delete | Spam | Edit</span>
</td>
然后使用jQuery代码:
Then the jQuery code:
$("comment_div").hover(
function() { $(".comment_actions").show(); },
function() { $(".comment_actions").hide(); }
);
这是可行的,除了我要拉出多个注释,并且无论悬停了什么注释,它只会在第一个div上显示菜单。我希望菜单仅针对当前注释显示我想我需要使用 $ this来完成这项工作,但我不确定如何使用。
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.
推荐答案
如果我没看错,格式应为-
If I'm reading that correctly, the format should be-
$(".comment_div").hover(
function() { $(this).children(".comment_actions").show(); },
function() { $(this).children(".comment_actions").hide(); }
);
这篇关于使用jQuery在鼠标悬停时显示隐藏类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文