简体   繁体   English

CSS切换与CSS更改

[英]css switching vs. css changing

I'd like to change the css of a page. 我想更改页面的CSS。 I see two ways of doing it : 我看到两种方法:

Using the Jquery .css function to change every tag in the html. 使用Jquery .css函数更改html中的每个标记。 example : 例如:

$("body").css("background : red")

Or disabling the current css stylesheet and enable a new one. 或者禁用当前的CSS样式表并启用一个新的样式表。

example: 例:

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 ;
      }
    }
  }
}

Which way is the more efficient ? 哪种方法更有效? Or maybe there is better ways ? 还是有更好的方法?

第三种选择是:为body一个额外的类,并在CSS中使用body.class2而不是使用第二个样式表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM