您不能直接使用jQuery更改CSS属性。但是你可以在至少两种方式实现相同的效果。
从文件动态加载CSS
function updateStyleSheet(filename) {
newstylesheet = "style_" + filename + ".css";
if ($("#dynamic_css").length == 0) {
$("head").append("")
css = $("head").children(":last");
css.attr({
id: "dynamic_css",rel: "stylesheet",type: "text/css",href: newstylesheet
});
} else {
$("#dynamic_css").attr("href",newstylesheet);
}
}
上面的示例复制自:
动态添加样式元素
$("head").append('');
var newStyleElement = $("head").children(':last');
newStyleElement.html('.red{background:green;}');