[英]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.