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;');

  • 相关阅读:
    29-赫夫曼树
    28-线索化二叉树
    27-顺序存储二叉树
    26-二叉树的遍历查找和删除
    25-二叉树的概念
    24-逻辑结构分析
    23-哈希表
    22-查找算法
    21-堆排序
    Mui-列表/table-view
  • 原文地址:https://www.cnblogs.com/jayruan/p/5093194.html
Copyright © 2011-2022 走看看