2
未定義我有一個小的功能,將採取CSS的字符串(如background: red; width: 145px; height: 145px;
) 並返回CSSStyleDeclaration
但如果我有一個background
屬性(background-color
等)的CSSStyleDeclaration
將有background-color
等集在Firefox中爲undefined
。背景的CSSStyleDeclaration在Firefox
_parseCSS: function(css) {
var div = document.createElement('div');
div.innerHTML = '<div style="' + css + '"></div>';
return div.childNodes[0].style
}
有人知道我在做什麼錯嗎?
編輯:這裏是不與Firefox瀏覽器的代碼:
style: function(style) {
var css = this._parseCSS(style);
return this.each(this._elem, function(element) {
this.each(css, function(s) {
var prop = s;
element.style[prop] = css[s];
});
});
},
參數style
是CSS的字符串。
適用於Firefox 3.6.9(fiddle [here](http://jsfiddle.net/U4DFA/))。什麼是您的瀏覽器版本? – 2010-11-22 21:39:57