我试图让我的函数正常工作,但没有成功。我所需要的只是能够滚动到我的 div 上并显示 X,然后我可以添加我想要的效果。
我正在使用 Javascript,因为我需要它跨浏览器兼容。我不想使用CSS,因为它对我将来想要添加的内容非常有限。
<script>
$(document).ready(function() {
$('div.userinfo').hover({
mouseenter: function() {
$(this).children('div.delete').show();
},
mouseleave: function() {
$(this).children('div.delete').hide();
}
});
});
</script>
<?
echo "<div class='userinfo'><div class='delete' style='cursor:pointer;position:relative;top:0px;float:right;padding-right:5px;' onclick=\"delete_('".$streamitem_data['streamitem_id']."');\">X</div></div>"
最佳答案
使用bind()方法而不是悬停:
$(document).ready(function() {
$('div.userinfo').bind({
mouseenter: function() {
$(this).children('div.delete').show();
},
mouseleave: function() {
$(this).children('div.delete').hide();
}
});
});
注意:如果您稍后使用 jQuery 添加新的 dom 元素,请使用 live()或on() ,如果你不是,请使用绑定(bind)方法,这是非常可靠的方法。
关于php - 鼠标输入悬停 Div 显示/隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11881597/