live() 鼠标输入/悬停
$('.WallEntry').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
$(this).find('.delButton').css('visibility', 'visible');
}else{
$(this).find('.delButton').css('visibility', 'hidden');
}
});
CSS:
.WallEntry{
width: 300px;
}
HTML
<div class='WallEntry'>
Message: <br>
Hi, have you been there..?
<div style='visibility: hidden' class='delButton'></div>
</div>
我想做的:
当您将鼠标悬停在消息(元素 WallEntry)上时,delButton 应该出现。当您将鼠标移开时,它应该隐藏起来。
我尝试过:
$(".WallEntry").live("hover", function(){
$(this).find('.delButton').css('visibility', 'visible');
}, function() {
$(this).find('.delButton').css('visibility', 'hidden');
});
但后来我被告知 live() 不处理两个函数。
我的代码在顶部的问题是它没有在带有 WallEntry 的附加 div 元素上显示 delButton。
这应该怎么做呢?
$('.WallEntry').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
$(this).find('.delButton').css('visibility', 'visible');
}else{
$(this).find('.delButton').css('visibility', 'hidden');
}
});
CSS:
.WallEntry{
width: 300px;
}
HTML
<div class='WallEntry'>
Message: <br>
Hi, have you been there..?
<div style='visibility: hidden' class='delButton'></div>
</div>
What I would like to do:
When you hover the message(the element WallEntry), the delButton should appear. When you mouseaway away, it should hide.
I have tried:
$(".WallEntry").live("hover", function(){
$(this).find('.delButton').css('visibility', 'visible');
}, function() {
$(this).find('.delButton').css('visibility', 'hidden');
});
But then I got told that live() doesnt handle two functions.
My code at top´s issue is that it doesn't show the delButton on the appended div elements with WallEntry.
How should this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议,如果您不需要支持 IE6,请删除所有悬停脚本,然后在 CSS 中执行此操作:
如果您有支持 IE6,请使用此 CSS:
以及此脚本:
或者,为了完全安全:
如果父容器有一个 ID,则
.delegate()< /code>
版本:
I suggest, if you don't need to support IE6, removing all of your script for the hover, and just doing this in CSS:
If you have to support IE6, use this CSS:
And this script:
Or, to be completely safe:
And if the parent container has an ID, the
.delegate()
version:可能不是你的问题,但你不能这样做:
May not be your problem, but couldn't you just do:
这是怎么回事?
如果您使用
display:none;
而不是visibility:hidden;
,我建议您这样做what's wrong with this?
I would suggest this if you were using
display:none;
instead ofvisibility:hidden;