自动内联CSS从CSS文件(jquery?ajax吗?php ?)

Automatically inline CSS from a CSS-file (jquery? ajax? php?)

本文关键字:CSS ajax php jquery 文件      更新时间:2023-09-26

由于我们不需要进入的原因,我需要将css文件的内容放入html页面的样式标记中。我想要自动完成,所以我需要读取CSS文件并将其内容放在标题中的样式标签中。

你知道怎么做吗?

最好是使用PHP, django, ASP.net或这个家族的东西。对于PHP,我将这样做:

<style id="Something">
<?php readfile("http://example.com/some/style.css"); ?>
</style>

但是如果你想使用jQuery,试试这个:

<style id="Something"></style>
<script type="text/javascript">
var request = $.ajax({
  url: "stylesheet.css",
});
request.done(function( msg ) {
  $( "style#Something" ).html( msg );
});
request.fail(function( jqXHR, textStatus ) {
  alert( "Request failed: " + textStatus );
});
</script>