javascript - 为什么无法通过javascript访问css中的z-index

标签 javascript css

我创建了一个id标签的按钮,当我点击它时,我希望它显示一个z-index为1的div。但是为什么z-index不能通过javascript访问:

var tag = document.getElementById('tag');
tag.onclick = function(){

   var tag_div = document.createElement("div");
   tag_div.id = "wow";
    document.body.appendChild(tag_div);
    tag_div.style.border = "1px solid black";
   tag_div.style.position = "absolute";
   tag_div.style.top = "200px";
   tag_div.style.left = "70px";
   tag_div.style.z-index = 1;
      return false;
}

最佳答案

样式表中的 CSS 规则使用连字符,CSS 属性 使用驼峰大小写,因此您需要 .zIndex

关于javascript - 为什么无法通过javascript访问css中的z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660342/

相关文章:

html - Opera 和 IE8 100% Height with bottom padding BUG

javascript - Django-Bootstrap4 Javascript、Jquery、CSS 无法正常工作

javascript - 在 Node js中加载本地jquery.js文件

javascript - 我如何在 custom.js 中收听 Prestashop 事件?

javascript - Livecycle Designer - 将文本字段链接到文本文件行

html - 移动 View map View 不正确?

javascript - Golang可以只使用HTML,CSS和JS吗?没有前端框架?

javascript - NodeJS 系统模块的文档在哪里

html - div溢出时如何自动使用滚动条

javascript - 如何自动为每个_blank 链接添加一个图标?