Changing CSS Values with Javascript

后端 未结 9 1527
借酒劲吻你
借酒劲吻你 2020-11-22 17:16

It\'s easy to set inline CSS values with javascript. If I want to change the width and I have html like this:

<
9条回答
  •  庸人自扰
    2020-11-22 17:45

    Perhaps try this:

    function CCSStylesheetRuleStyle(stylesheet, selectorText, style, value){
      var CCSstyle = undefined, rules;
      for(var m in document.styleSheets){
        if(document.styleSheets[m].href.indexOf(stylesheet) != -1){
         rules = document.styleSheets[m][document.all ? 'rules' : 'cssRules'];
         for(var n in rules){
           if(rules[n].selectorText == selectorText){
             CCSstyle = rules[n].style;
             break;
           }
         }
         break;
        }
      }
      if(value == undefined)
        return CCSstyle[style]
      else
        return CCSstyle[style] = value
    }
    

提交回复
热议问题