使用CSS或Javascript显示和隐藏DIV?

使用CSS或Javascript显示和隐藏DIV?,javascript,jquery,Javascript,Jquery,我刚刚看到一个演示,它有这个jquery代码来显示和隐藏悬停时的俯冲,但这不能用常规css来完成吗?如果你能用css实现,用javascript实现有什么好处吗 $('.comment').hover(function() { $(this).children('.delete').show(); }, function() { $(this).children('.delete').hide(); }); 您可以使用CSS实现这一点,但IE6只支持锚定标记(A)上的:hover伪类,

我刚刚看到一个演示,它有这个jquery代码来显示和隐藏悬停时的俯冲,但这不能用常规css来完成吗?如果你能用css实现,用javascript实现有什么好处吗

$('.comment').hover(function() {
  $(this).children('.delete').show();
}, function() {
  $(this).children('.delete').hide();
});

您可以使用CSS实现这一点,但IE6只支持锚定标记(A)上的:hover伪类,因此它并不常见。

CSS hover可以与锚定标记一起使用,但IE6无法识别诸如li标记之类的悬停事件

但是,如果使用锚定标记,则可以在CSS中实现相同的效果:

a.comment       .delete { display: none; }
a.comment:hover .delete { display: block; }

乔迪是对的。查看CSS属性的文档。

悬停将提供更多功能。如果您为其提供2个以上的功能,它将循环使用所有功能。 范例

这将在第一次悬停时显示一组子对象,然后隐藏,下次显示另一组子对象


鼠标悬停功能也适用于多个元素,只有当鼠标离开所有元素时(不仅仅是当鼠标离开一个元素并移动到另一个元素时)才会触发鼠标悬停功能。

我在服务器端动态创建类似的内容。我相信有一种更有效/更漂亮的方法,但这通常能满足我的需要。基本上隐藏所有div,取消隐藏需要显示的div(在onClick事件的函数中作为arg传递)


正确,但在这种情况下,:hover可以用于
a
标记,但我们现在还不知道,因为提问者没有包含任何标记。+1第一个很好的答案:)我编辑了它,并改为IE6,因为7和8确实支持
:在
a
以外的元素上悬停
…昨天一条评论将类似的问题指向doctype.com!
$('.comment').hover(
    function(){$(this).children('.delete.first').show()},
    function(){$(this).children('.delete.first').hide()},
    function(){$(this).children('.delete.second').show()},
    function(){$(this).children('.delete.second').hide()}
    );
function toggleTab(id)
{
    document.getElementById('divEnrollment').style.display='none';    
    document.getElementById('divSearch').style.display='none';
    document.getElementById('divMeeting').style.display='none';
    document.getElementById('divBenefit').style.display='none';
    document.getElementById('div' + id).style.display='block';

    document.getElementById('spnEnrollment').style.color='blue';    
    document.getElementById('spnSearch').style.color='blue';
    document.getElementById('spnMeeting').style.color='blue';
    document.getElementById('spnBenefit').style.color='blue';
    document.getElementById('spn'+id).style.color = 'red';
}