【发布时间】:2013-02-17 12:55:36
【问题描述】:
我有不同样式的网页,用户可以随时更改和构建。 我有这段代码可以与浏览器 IE-9+、chrome、FF、safari 一起使用。
if($("#customCss").length>0)
$("#customCss").empty();
$("#customCss").text(css_txt );
$('head').append('<style type="text/css" id="customCss"> ' + css_txt + '</style>');
我想让网站适合 IE-7,8。但是此代码不适用于 IE-7,8。我收到此错误代码:
Microsoft JScript runtime error: Unexpected call to method or property access.
在这个 jquery func jquery 中:
append: function () {
return this.domManip(arguments, true, function (elem) {
if (this.nodeType === 1) {
this.appendChild(elem);
}
});
},
我也试过这个,但没有运气:
document.getElementById("customCss").innerHTML=css_txt;
知道为什么吗?
【问题讨论】:
-
尝试使用
.textContent而不是.innerHTML。 -
也许您应该先尝试定义
<style type="text/css" id="customCss">,然后再尝试使用$("#customCss").text(css_txt );设置其内容。您也可以考虑在 onLoad 上运行代码,以确保 #customCss 元素存在于 DOM 中。
标签: javascript jquery css coding-style stylesheet