[英]css switching vs. css changing
我想更改页面的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 ;
}
}
}
}
哪种方法更有效? 还是有更好的方法?
第三种选择是:为body
一个额外的类,并在CSS中使用body.class2
而不是使用第二个样式表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.