Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查当前样式表的jqueryif语句_Jquery_Html_Css - Fatal编程技术网

检查当前样式表的jqueryif语句

检查当前样式表的jqueryif语句,jquery,html,css,Jquery,Html,Css,我正在开发一个web应用程序,并切换样式表,让用户选择不同的主题 我有休闲代码: $('#theme_selector_white').click(function (){ $('link[href="default_teal.css"]').attr('href','white_style.css'); }); $('#theme_selector_teal').click(function (){ $('link[href="white_style.css"]').attr('h

我正在开发一个web应用程序,并切换样式表,让用户选择不同的主题

我有休闲代码:

$('#theme_selector_white').click(function (){
   $('link[href="default_teal.css"]').attr('href','white_style.css');
});
$('#theme_selector_teal').click(function (){
   $('link[href="white_style.css"]').attr('href','default_teal.css');
});  
$('#theme_selector_sopia').click(function (){
   $('link[href="    "]').attr('href','sopia_style.css');
});
如果交替使用两个不同的样式表,我的代码可以工作,但是一旦我添加了第三个样式表,我需要检查当前的样式表是什么,这样我就可以用预期的样式表替换当前的样式表

我相信我需要为每个选择者做类似的事情:

$('#theme_selector_white').click(function(){
     if ( current stylesheet == "default_teal.css") {
           //replace default_teal.css with intended stylesheet
     }
     else {
          //replace sopia_style.css with intended stylesheet

     }
我需要帮助写条件来检查当前的样式表


我将非常感谢你的帮助

为链接元素提供一个id

<link id="userSelectedCss" ...>

为链接元素提供一个id

<link id="userSelectedCss" ...>

这是干溶液。首先,正如Travis所说,给链接一个ID:

<link id="userSelectedCss" rel="stylesheet" ...>

这是干溶液。首先,正如Travis所说,给链接一个ID:

<link id="userSelectedCss" rel="stylesheet" ...>

然后我应该在html文件中有三个不同的链接元素吗?然后我应该在html文件中有三个不同的链接元素吗?记住
事件.preventDefault()
返回false
以避免滚动记住
事件.preventDefault()
返回false
以避免滚动
$(".theme_selector").click(function(e) {
    e.preventDefault(); // Override the normal link click action.
    $("#userSelectedCss").attr("href", $(this).data("css"));
});