原生JS获取元素css属性

JS获取元素样式表:

var style = null;
    if (window.getComputedStyle) {     //判断浏览器类型
        style = window.getComputedStyle(box, null);    // 非IE
    } else {
        style = box.currentStyle;  // IE
    };

所有的样式都是style的属性
例如:
元素宽度:style.width,
元素高度:style.height

猜你喜欢

转载自blog.csdn.net/qq_36427929/article/details/77920818