zoukankan      html  css  js  c++  java
  • 获取css style值

    var obj=document.getElementById("btn");
    var currentStyle=null;
    if(obj.currentStyle){
    currentStyle=obj.currentStyle;
    }else{
    currentStyle=window.getComputedStyle(obj,null);
    }
    alert(currentStyle.width);

    var addCssRule = function() {
    // 创建一个 style, 返回其 stylesheet 对象
    // 注意:IE6/7/8中使用 style.stylesheet,其它浏览器 style.sheet
    function createStyleSheet() {
    var head = document.head || document.getElementsByTagName('head')[0];
    var style = document.createElement('style');
    style.type = 'text/css';
    head.appendChild(style);
    console.dir(style)
    return style.sheet ||style.styleSheet;
    }

    // 创建 stylesheet 对象
    var sheet = createStyleSheet();

    // 返回接口函数
    return function(selector, rules, index) {
    index = index || 0;
    if (sheet.insertRule) {
    sheet.insertRule(selector + "{" + rules + "}", index);
    } else if (sheet.addRule) {
    sheet.addRule(selector, rules, index);
    }
    }
    }();

    addCssRule('p', 'color:red;border:1px solid gray;');
    addCssRule('div', 'color:yellow;border:1px solid gray;');

  • 相关阅读:
    Python Day23
    Python Day22
    Python Day21
    Python Day20
    Python Day19
    Python Day18
    Python Day17
    Python Day15
    Appium python unittest pageobject如何实现加载多个case
    Appium python Uiautomator2 多进程问题
  • 原文地址:https://www.cnblogs.com/jayruan/p/5093194.html
Copyright © 2011-2022 走看看