11

我对 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”来完成这项工作,但我不确定如何。

4

2 回答 2

18

如果我没看错,格式应该是——

$(".comment_div").hover(
  function() { $(this).children(".comment_actions").show(); },
  function() { $(this).children(".comment_actions").hide(); }
);
于 2009-09-19T21:37:15.117 回答
2

像这样的东西对我有用:

<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>

但是,您将面临的问题是将悬停动作悬停在具有display: none; set. 您可能需要考虑将其包装在对鼠标敏感的东西中,然后改为显示/隐藏子项。

于 2009-09-19T21:49:00.623 回答