1
我想更改页面的css。我看到了两种方法:css切换与css转换
使用Jquery .css
函数更改html中的每个标记。 例如:
$("body").css("background : red")
或禁用当前的CSS样式表,并启用一个新的。
例如:
function switch_style (css_title)
{
// You may use this script on your site free of charge provided
// you do not remove this notice or the URL below. Script from
// http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
var i, link_tag ;
for (i = 0, link_tag = document.getElementsByTagName("link") ;
i < link_tag.length ; i++) {
if ((link_tag[i].rel.indexOf("stylesheet") != -1) &&
link_tag[i].title) {
link_tag[i].disabled = true ;
if (link_tag[i].title == css_title) {
link_tag[i].disabled = false ;
}
}
}
}
哪种方法更有效? 或者也许有更好的方法?
还有第三种选择:在CSS中给'body'一个额外的类并使用'body.class2',而不是使用第二个样式表。 –
@TomvanderWoerdt - 做出答案。 – Aiias
@TomvanderWoerdt你应该把这个作为答案:) – WooCaSh