[英]Convert external and internal styles into inline styles with javascript
In order to make html content with styles more portable, I need to convert all external styles ( <link>
importing external .css) and internal styles (defined with <style>
s) into the inline styles of the elements. 为了使具有样式的html内容更具可移植性,我需要将所有外部样式( <link>
导入外部.css)和内部样式(由<style>
定义)转换为元素的内联样式。
For example, if I have: 例如,如果我有:
<link rel="stylesheet" href="common.css">
<style>
.alert { color: red; font-weight: bold; }
</style>
<div id="foo" class="special alert" style="font-size: 2em;">something</div>
and a common.css with: 和common.css与:
.special { border: 1px solid dotted; }
I want a result like: 我想要这样的结果:
<div id="foo" class="special alert" style="border: 1px solid dotted; color: red; font-weight: bold; font-size: 2em;">something</div>
Currently the problem is how to get all external and internal styles that are applied to the div[#foo]? 当前的问题是如何获取应用于div [#foo]的所有外部和内部样式?
How many CSS properties do you have? 您有几个CSS属性? if not so many, you can do something like $("#foo").css("border", "1px"); 如果不是很多,您可以执行类似$(“#foo”)。css(“ border”,“ 1px”);
if there are a lot of CSS files, its always not suggested do inline style 如果有很多CSS文件,则始终不建议使用内联样式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.