zoukankan      html  css  js  c++  java
  • css()获取样式当前值和设置样式的简单封装

    获取CSS样式或设置CSS样式,兼容IE,参数一:元素对象,参数二:属性名,参数三(可选):属性值
     
     
    function css() {
        if (arguments.length == 2) {
            //获取样式
            if (getComputedStyle(arguments[0], false)) {
                //标准浏览器
                var attr = arguments[1];
                return getComputedStyle(arguments[0], false)[attr];
            } else {
                //ie8-
                var attr = arguments[1];
                return arguments[0].currentStyle[attr];
            }
        } else if (arguments.length == 3) {
            //设置样式 box.style.display = 'none'
            var attr = arguments[1];
            arguments[0].style[attr] = arguments[2];
        }
    }
  • 相关阅读:
    leetcode122
    leetcode121
    leetcode773
    leetcode803
    leetcode658
    leetcode723
    leetcode134
    leetcode340
    leetcode721
    leetcode362
  • 原文地址:https://www.cnblogs.com/muyun123/p/11503487.html
Copyright © 2011-2022 走看看