如何使用jQuery在悬停时设置z-index?
如何设置img元素悬停时的z索引?当鼠标指针位于img之外时,z索引必须为0,否则应为9 我知道如何设置它,但不知道如何在悬停时更改它如何使用jQuery在悬停时设置z-index?,jquery,html,css,z-index,Jquery,Html,Css,Z Index,如何设置img元素悬停时的z索引?当鼠标指针位于img之外时,z索引必须为0,否则应为9 我知道如何设置它,但不知道如何在悬停时更改它 $('#content img').click(function () { $(this).css("z-index", "99") }); 仅css的解决方案: #content img{ z-index:0; } #content img:hover{ z-index:9; } 试试这个 $('#content img').
$('#content img').click(function () {
$(this).css("z-index", "99")
});
仅css的解决方案:
#content img{
z-index:0;
}
#content img:hover{
z-index:9;
}
试试这个
$('#content img').hover(
function() {
$(this).css("z-index", "99")
},
function() {
$(this).css("z-index", "0")
});
编辑:分号不是必需的,但无论如何还是要感谢:-)为什么要用另一个问题来回答这个问题?
$('#content img').hover(
function() {
$(this).css("z-index", "99")
},
function() {
$(this).css("z-index", "0")
});