jquery怎样查询z-index

javascriptjavascript 2023-08-29 16:16:12 637
摘要: jquery怎样查询z-indexcss()方法设置或返回被选元素的一个或多个样式属性。返回指定的CSS属性的值,语法如下:css("propertyname");示例如下:<html><head><scriptsrc="/jquery/jquery-1.11.1.min.js"></script><sc...

jquery怎样查询z-index

css() 方法设置或返回被选元素的一个或多个样式属性。

返回指定的 CSS 属性的值,语法如下:

css("propertyname");

示例如下:

<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    alert("z-index = " + $("img").css("z-index"));
  });
});
</script>
<style type="text/css">
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<img src="/i/eg_smile.gif" />
<p>由于图像的 z-index 是 -1,因此它在文本的后面出现。</p>
<button>返回img元素的z-index</button>
</body>
</html>

输出结果:

05.png

点击按钮后:

06.png

相关视频教程推荐:jQuery视频教程