如何使用jQuery切换我的CSS样式表? [英] How do I switch my CSS stylesheet using jQuery?

查看:141
本文介绍了如何使用jQuery切换我的CSS样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作很简单。



您点击(id =themes),它打开一个向下滑动并列出主题的div (id =themedrop)。 (此时我只有两个)

 < button id =original> Original< / button> br /> 
< button id =grayscale>灰度< / button>

现在当网站加载时,它会加载style1.css(main / original theme)

 < link rel =stylesheettype =text / csshref =style1.css> 

现在我想知道的是...
如何单击灰度按钮将样式表从style1.css更改为style2.css(注意:文件在同一目录中)



任何帮助都会很多赞赏。

解决方案

  $('#grayscale' 
$('link [href =style1.css]')。attr('href','style2.css');
});
$('#original')。click(function(){
$('link [href =style2.css]')。attr('href','style1.css') ;
});

尝试一下,但不知道是否可以工作我没有测试它,但gd运气。 / p>

What I'm working on is simple.

You click on a button (id="themes") and it opens up a div (id="themedrop") that slides down and lists the themes. (I only have two at this point)

<button id="original">Original</button><br />
<button id="grayscale">Grayscale</button>

Now when the site is loaded it loads with style1.css (main/original theme)

<link rel="stylesheet" type="text/css" href="style1.css">

Now what I'm trying to figure out is... How can I have it that when the grayscale button is clicked to change the stylesheet from style1.css to style2.css (note: files are in the same directory)

Any help would be much appreciated.

解决方案

$('#grayscale').click(function (){
   $('link[href="style1.css"]').attr('href','style2.css');
});
$('#original').click(function (){
   $('link[href="style2.css"]').attr('href','style1.css');
});

Give this a try but not sure if it will work I have not tested it but gd luck.

这篇关于如何使用jQuery切换我的CSS样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆