让DIV显示在最底层 - 小众知识

让DIV显示在最底层

2014-07-10 03:27:49 苏内容
  标签: DIV/底层
阅读:4208
<html>
<head>
<title></title>
<script>
function plusDiv() {
  var div1 = document.getElementById('div1');
  var div2 = document.getElementById('div2');
  if (div1.style.zIndex > div2.style.zIndex) {
    div1.style.zIndex = div1.style.zIndex - 2;
  } else {
    div2.style.zIndex = div2.style.zIndex - 2;
  }
}
</script>
</head>
<body>
<div id="div1" style="position:absolute;z-index:1;width:100;height:100;background-color:#FF0000;left:0;top:0"></div>
<div id="div2" style="position:absolute;z-index:2;width:100;height:100;background-color:#00FF00;left:10;top:10"></div>
<input type="button" onclick="plusDiv()" value="交替底层出现" style="z-index:100;position:absolute;left:300" />
</body>
</html>
扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1