x
首页 前端[Javascript] 用Js修改样式表规则_解决IE6下PNG透明,操作css规则

用Js修改样式表规则_解决IE6下PNG透明,操作css规则

发表于 2012-04-04 - 浏览:3170 评论:0 收藏 0

function getPseudoRule(rule, css){
  var sheet = document.styleSheets[0];
  var rules = sheet.cssRules||sheet.rules;
  for (var i=0,l=rules.length;i   if(rules[i].selectorText==rule)return rules[i].style[css];
  }
  return '';
 }
 function setPseudoRule(rule, key, value){
  var sheet = document.styleSheets[0];
  var rules = sheet.cssRules||sheet.rules;
  for (var i=0,l=rules.length;i   if(rules[i].selectorText==rule)rules[i].style[key]=value;
  }
 }
 if(isIE6){
  var url=$('user_name').currentStyle.backgroundImage;
  var ie6Url = url.substring(5,url.length-2);
  setPseudoRule('.userTypes','filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src='"+ie6Url+"')");
  setPseudoRule('.userTypes','background',"none");
 }
 setPseudoRule('#user_name','backgroundColor','red');
 setPseudoRule('.userTypes','backgroundColor','red');
 setPseudoRule('.userTypes B','color','green');

var ele=document.createElement('div');
 ele.className = 'userTypes';
 document.body.appendChild(ele);

文章评论。。。