js操作styleSheets

Base.prototype.addRule = function (num, selectorText, cssText, position) {
	var sheet = document.styleSheets[num];
	if (typeof sheet.insertRule != 'undefined') {
	       sheet.insertRule(selectorText + "{" + cssText + "}", position);
	} else if (typeof sheet.addRule != 'undefined') {
	       sheet.addRule(selectorText, cssText, position);
	}
};
//移除link 或style 中的CSS 规则
Base.prototype.removeRule = function (num, index) {
	var sheet = document.styleSheets[num];
	if (typeof sheet.deleteRule != 'undefined') {
	       sheet.deleteRule(index);
	} else if (typeof sheet.removeRule) {
	       sheet.removeRule(index);
	}
	return this;
};

 

posted @ 2016-04-25 00:58  天桥残局  阅读(586)  评论(0编辑  收藏  举报