首頁  >  文章  >  web前端  >  jquery怎樣查詢z-index

jquery怎樣查詢z-index

WBOY
WBOY原創
2021-12-29 13:57:492291瀏覽

jquery查詢元素「z-index」的方法:1、利用「$(元素)」語句取得指定的元素物件;2、利用css()方法傳回指定元素的「z-index」屬性值,語法為「元素物件.css("z-index")」。

jquery怎樣查詢z-index

本教學操作環境:windows10系統、jquery3.2.1版本、Dell G3電腦。

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" / alt="jquery怎樣查詢z-index" >
<p>由于图像的 z-index 是 -1,因此它在文本的后面出现。</p>
<button>返回img元素的z-index</button>
</body>
</html>

輸出結果:

jquery怎樣查詢z-index

點選按鈕後:

jquery怎樣查詢z-index

相關影片教學推薦:jQuery影片教學

以上是jquery怎樣查詢z-index的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn