我想创建一个这样的样式表:
var sheet = document.createElement('style'); sheet.type = 'text/css';
sheet.innerHTML = data.style;
但似乎IE 需要自己的语法。为了简化这个答案的代码,我试过了
var sheet = document.createElement('style'); sheet.type = 'text/css';
(sheet.styleSheet ? sheet.styleSheet.cssText : sheet.innerHTML) = data.style;
但这会引发ReferenceError: invalid assignment left-hand side
.
那么,我必须使用...
var sheet = document.createElement('style'); sheet.type = 'text/css';
if(sheet.styleSheet) sheet.styleSheet.cssText = data.style;
else sheet.innerHTML = data.style;
...还是有更简单的选择?