zoukankan      html  css  js  c++  java
  • JS获取非行内样式

    最近遇到的一个问题,如何获取非行内样式,如果用普通方式console的话是拿不到数值的

    需要使用currentStyle获取才可以在console台拿到数据

     var timers = document.getElementsByClassName("time-out")[0];
    
     if (timers.currentStyle) {
            this.conswidth = timers.currentStyle.width;
            this.consheight = timers.currentStyle.height;
          } else {
            this.conswidth = getComputedStyle(timers, null).width;
            this.consheight = getComputedStyle(timers, null).height;
          }

    else为兼容IE浏览器方法,其中传的两个参数,一个为获取到的div,另一个无实际作用,直接传null即可

    此时在console台打印this.conswidth就可以准确的拿到数值了

  • 相关阅读:
    dart 函数迭代器
    dart 编译
    dart 扩展方法
    dart 包
    默认2345导航
    (24)WPF 数据绑定
    (22)WPF 控件模板
    JSP慕课网之Session
    HTML <td> 标签的 colspan 属性
    HTML Input属性
  • 原文地址:https://www.cnblogs.com/wangziwei/p/13889114.html
Copyright © 2011-2022 走看看