我有两个样式表,用户可以选择分别加载它们。我的样式表是:one.css、two.css。我想要的是:如果用户更改主题,我希望内容也随之更改。 我所做的是:
function strcmp ( str1, str2 ) {
return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) ;
}
(function(){
var href = $('link').attr('href');
console.log(href); // check what style-sheet
if(strcmp(href,'one')==0)
$("#p1").html('this is the content for one.css');
$("#p1").append("still for one.css");
else if(strcmp(href,'two')==0)
$("#p1").html('this is the content for two.css');
$("#p1").append("still for two.css");
})();
我的方法行不通,有什么想法吗?
最佳答案
href 必须是“one.css”而不仅仅是“one”
试试这个:
if(strcmp(href,'one.css')==0)
关于javascript - 如何根据样式表将内容加载到html元素中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16605361/