当同一辅助函数检索到其他属性时,不会检索z-index属性

时间:2013-10-14 17:28:06

标签: javascript css dom browser z-index

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="20000;http://new-url/" id="meta-refresh">
<style type="text/css">
#test{
width: 100px;
height: 80px;
background-color: yellow;
opacity:0.5;
z-index:3;

}
</style>
  <title>Add Properties</title>
  <!--link rel="stylesheet" href="qunit-1.12.0.css"-->
</head>
<body>
  <div id="test">This is some text</div>
  <p>Properties</p>
  <script>
  function getStyle(el, cssprop){
 if (el.currentStyle) //IE
  return el.currentStyle[cssprop]
 else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
  return document.defaultView.getComputedStyle(el, "")[cssprop]
 else //try and get inline style
  return el.style[cssprop]
}
    console.log("1"+navigator.appVersion);
    console.log("2"+navigator.platform);
    console.log("3"+history.length);
    console.log("4"+parent.top.document.referrer);
     metatags = document.getElementsByTagName("meta");  
   var content = metatags[0].getAttribute("content");
    var mr = document.getElementById("meta-refresh");
    console.log("Meta Refresh"+ content);
    console.log(navigator.plugins);
    console.log(navigator.plugins.length);
    var mydiv = document.getElementById("test");
    console.log(getStyle(mydiv,'width'));
    console.log(getStyle(mydiv,'opacity'));
    console.log(getStyle(mydiv,'z-index'));
    var d = new Date()
    var n = d.getTimezoneOffset();
    console.log(n);


    </script>
</body>
</html>

这是代码,所有属性(如宽度不透明度)显示适当的值,但z-index给出 undefined 值。我尝试了'z-index'以及“zindex”。请帮助我有这个问题。

提前致谢 斯瓦拉杰

1 个答案:

答案 0 :(得分:2)

  

我尝试了z-index以及zindex

关闭,但它是zIndexCSSStyleDeclarations的属性(例如.stylegetComputedStyle()返回的)的属性是驼峰式的。您也可以使用.getPropertyValue("z-index")