0
<!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 给出了一个未定义的值。我尝试了“z-index”以及“zindex”。请帮我解决这个问题。

提前感谢斯瓦拉吉

4

1 回答 1

2

我试过z-indexzindex

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

于 2013-10-14T17:33:20.887 回答