简体   繁体   English

如何根据样式表将内容加载到html元素中?

[英]How to load content into html elements according to style-sheet?

I'm having two style-sheets which can be loaded each by the user choice. 我有两个样式表,每个样式表都可以由用户选择加载。 My style-sheets are: one.css, two.css. 我的样式表是:one.css,two.css。 What I want is: If the user change the theme I want the content to be changed too. 我想要的是:如果用户更改主题,我也希望更改内容。 What I did is: 我所做的是:

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");     

          })();

My method is not working, any ideas? 我的方法不起作用,有什么想法吗?

the href must be "one.css" and not just "one" href必须是“ one.css”,而不仅仅是“ one”

try this: 尝试这个:

if(strcmp(href,'one.css')==0)

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

相关问题 如何基于设备加载样式表和Java脚本以及j查询 - how to load style-sheet and java script and j query based on device 在 web 组件中添加动态样式表 - dynamic style-sheet adding in web component 外部样式表定义的未重置样式 - Un-reset Styles Defined by External Style-Sheet 拒绝从...应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查 - Refused to apply style from... because its MIME type ('text/html') is not a supported style-sheet MIME type, and strict MIME checking is enabled 无法使用document.querySelector…或document.getElementById从内部样式表中获取属性 - Can not get attributes from internal style-sheet with document.querySelector… or document.getElementById 如何根据内容控制html模板输出? - How to control html template output according to the content? 如何使用CSS样式安全地加载电子邮件内容 - How to securely load email content with css style 无法通过内容脚本使用jQuery更改HTML元素的样式 - Cannot change style of HTML elements using jQuery by content script 如何设置传递给 MDXRenderer 的 HTML 元素的样式? - How to style HTML elements passed into MDXRenderer? Highcharts 如何将内联样式添加到 HTML 元素? - How is inline style added to HTML elements by Highcharts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM