Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery在悬停时设置z-index?_Jquery_Html_Css_Z Index - Fatal编程技术网

如何使用jQuery在悬停时设置z-index?

如何使用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').

如何设置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').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")
   });