使用jQuery在悬停时显示隐藏类

使用jQuery在悬停时显示隐藏类,jquery,class,hover,Jquery,Class,Hover,我对jQuery比较陌生,我希望能够在鼠标上方显示菜单 以下是HTML内容: <td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/> <span class="comment_actions"> Approve | Delete | Spam | Edit</span> </td> 这是可行的,除了我正在拉出多个注释,无论悬

我对jQuery比较陌生,我希望能够在鼠标上方显示菜单

以下是HTML内容:

<td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/>
    <span class="comment_actions"> Approve | Delete | Spam | Edit</span>
</td>

这是可行的,除了我正在拉出多个注释,无论悬停什么“注释”,这只会在第一个div上显示菜单。我想让菜单只显示当前悬停的评论。我想我需要使用“$this”来实现这一点,但我不确定如何实现。

如果我读对了,格式应该是-

$(".comment_div").hover(
  function() { $(this).children(".comment_actions").show(); },
  function() { $(this).children(".comment_actions").hide(); }
);

类似这样的东西对我很有用:

<script>
    $(document).ready(function() {
        $(".container").hover(
            function() { $(this).children('.comment_actions').show(); },
            function() { $(this).children('.comment_actions').hide(); }
        );
    });

</script>

<style>
</style>

<table border="1">
    <tr>
        <td class ="container"><br/>
            asd<span class="comment_actions">Approve | Delete</span>
        </td>
        <td class ="container"><br/>
            asd <span class="comment_actions">Approve | Delete</span>
        </td>
        <td class ="container"><br/>
            asd<span class="comment_actions"> Approve| Delete</span>
        </td>
    </tr>
</table>

$(文档).ready(函数(){
$(“.container”)。悬停(
函数(){$(this).children('.comment_actions').show();},
函数(){$(this).children('.comment_actions').hide();}
);
});

asdaprove |删除
asd批准|删除
asd批准|删除

但是,您将面临的问题是将操作悬停在具有
display:none;设置
。您可能想考虑将其包装在鼠标敏感的东西上,然后显示/隐藏孩子。

难道不会显示/隐藏“评论”吗?我试图在hover上显示/隐藏“评论动作”。你完全正确-我今天半睡半醒,没有练习。现在应该修好了。太好了再次为这里的失误感到抱歉。
<script>
    $(document).ready(function() {
        $(".container").hover(
            function() { $(this).children('.comment_actions').show(); },
            function() { $(this).children('.comment_actions').hide(); }
        );
    });

</script>

<style>
</style>

<table border="1">
    <tr>
        <td class ="container"><br/>
            asd<span class="comment_actions">Approve | Delete</span>
        </td>
        <td class ="container"><br/>
            asd <span class="comment_actions">Approve | Delete</span>
        </td>
        <td class ="container"><br/>
            asd<span class="comment_actions"> Approve| Delete</span>
        </td>
    </tr>
</table>