<script type="text/javascript">
(function () {
if (window.CSSStyleSheet) {
var wc = window.CSSStyleSheet.prototype;
wc.addRule = function (a, b) {
var wc = this;
wc.insertRule(a + "{" + b + "}", wc.cssRules.length);
};
wc.removeRule = function (a) {
var wc = this;
wc.deleteRule(a);
};
wc.__defineGetter__("rules", new Function("return this.cssRules"));
}
})(); var addRule = function (a, b) {
var wc = document.styleSheets[0], i;
for (i = 0 ; i < wc.rules.length ; i ++) if (wc.rules[i].selectorText == a) wc.removeRule(i);
wc.addRule(a, b);
};
var add = function () {
var wc = document.getElementById("wc").value;
if (/([^\{]+)\s*(\{[^}]+\})/.test(wc)) {
addRule(RegExp.$1, RegExp.$2);
} else {
alert("样式错误");
}
};
</script> 我的问题就是想问在window.CSSStyleSheet中这个CSSStyleSheet属性是什么?还有就是document.styleSheets[0]中的styleSheets属性数组又是表示什么?感觉JS中有很多类似对象的属性都很莫名奇妙,而且我查手册也查不到
CSSStyleSheet是自定义的全局对象..
document.styleSheets[0] 是指代CSS样式表的第一个样式
styleSheets才是IE的.
你查手册肯定能查到的.注:手册是IE的.
JavaScriptDOM高级程序设计
Document.styleSheet
一组关联于文档的样式表片段集合.
参考
http://seahorsedad.blog.hexun.com/33236162_d.html
http://msdn.microsoft.com/en-us/library/dd347054(VS.85).aspxstyleSheets
http://msdn.microsoft.com/en-us/library/ms531200(VS.85).aspx
window.CSSStyleSheet通同styleSheets
if (window.CSSStyleSheet)这一部分的代码段是针对FF浏览器的?
下面才是针对IE浏览器的?
所以应该是判断浏览器支持window.CSSStyleSheet不.