是否可以从外部样式表中提取所有样式并将它们放在同一页面上?
是否可以使用 javascript 或 jQuery 提取外部文件中列出的所有 CSS 规则,然后执行 $('link').remove()
,然后将所有 CSS 规则放在样式块中同一页面?
澄清一下:我想用 JavaScript 将所有外部 CSS 规则移动到页面中的内联样式块中,是的。
如果是这样,我该如何实现这一目标?
Is it possible with javascript or jQuery to pull in all CSS rules that are listed in external files, then do $('link').remove()
, then put all the CSS rules in style blocks on the same page?
To clarify: I want to move all external CSS rules into inline style blocks in the page with JavaScript, yes.
If so, how might I go about accomplishing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我省略了有关将规则附加为“内联”规则的详细信息。这应该是相当微不足道的。另外,您将在下面看到我已禁用样式表而不是实际删除它们。我想强调的重要一点是,该解决方案允许导入其他样式表的样式表。
TEST.HTML
screen.css
I've left out the details about appending the rules as "inline" rules. That should be fairly trivial. Also, you'll see below I have DISABLED the style sheets rather than actually removing them. the important thing I want to hilight is that this solution allows for stylesheets that import other stylesheets.
TEST.HTML
screen.css
那么你可以这样做:
请记住,这会弄乱加载样式表中图像/字体的相对路径。
Well you could do something like:
Keep in mind that this will screw up relative paths to images/fonts in loaded stylesheets.