简体   繁体   English

在CSS文件中添加前缀

[英]Add a prefix to a CSS file

I have this code which allows me to swap prefixes of images which works great thanks to maniator! 我有这段代码,允许我交换图像的前缀,这要感谢maniator!

    $(function() {
    $('img.swap').each(function(){     
    $(this).data('current_image', this.src);     
}) 
$('a').click(function(){          
        var prefix = $(this).attr("class");       
         $('img.swap').each(       
         function() {           
            if($(this).data('prefix') != prefix){            
            this.src = $(this).data('current_image').replace('.gif', (prefix)+'.gif');
            $(this).data('prefix', prefix)          
    }         
     else {            
     this.src = $(this).data('current_image');           
      $(this).data('prefix', '')          
      }       
       });  
      }); 
 });

My question is am I able to add the same prefix which is being added to the image to a certain CSS file, in this instance it will be color.css so could I make it color_bw.css? 我的问题是我可以将添加到图像的前缀添加到某个CSS文件中吗,在这种情况下,它将是color.css,所以我可以将其设置为color_bw.css吗?

Many Thanks 非常感谢

yes the link tag that links the css is the same as anyother element 是的,链接css的链接标记与其他任何元素相同

set the href like this 像这样设置href

<link id="css" rel="stylesheet" href="styles/reset.css" type="text/css" />

var css = $("#css").attr("href");
var href = css.replace(".css",css+prefix);
$("#css").attr("href",href);

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

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