I am relatively new to JQuery and I would like to be able to show a menu on mouseover.
我对JQuery相对较新,我希望能够在鼠标悬停时显示菜单。
Here is the html
这是html
<td class ="comment_div"> <?php echo("$comment_data['comment']); ?> <br/>
<span class="comment_actions"> Approve | Delete | Spam | Edit</span>
</td>
Then the JQuery
然后是JQuery
$("comment_div").hover(
function() { $(".comment_actions").show(); },
function() { $(".comment_actions").hide(); }
);
This works exept for I'm pulling multiple comments out and this only will show the menu on the first div no matter what "comment" is hoverd. I would like to to have the menu show only for the comment that is currently being hoverd over. I think I need to use "$this" to make this work but not sure how.
这项工作是因为我将多个评论拉出来,这只会显示第一个div上的菜单,无论“评论”是什么。我想将菜单显示仅用于当前正在悬停的评论。我想我需要用“$ this”来完成这项工作,但不知道如何。
Thanks.
谢谢。
2 个解决方案
#1
18
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(); }
);
Edit because i'm a complete idiot.
编辑,因为我是一个完全白痴。
#2
2
Something like this works for me:
这样的东西适合我:
<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>
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.
但是,您将面临的问题是将悬停操作覆盖在具有display:none的div上;组。您可能需要考虑将其包装在鼠标敏感的内容中,然后显示/隐藏子项。
#1
18
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(); }
);
Edit because i'm a complete idiot.
编辑,因为我是一个完全白痴。
#2
2
Something like this works for me:
这样的东西适合我:
<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>
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.
但是,您将面临的问题是将悬停操作覆盖在具有display:none的div上;组。您可能需要考虑将其包装在鼠标敏感的内容中,然后显示/隐藏子项。