jQuery:使用html mimetype加载包含css样式表的html文件

时间:2014-09-24 04:33:24

标签: jquery css mime-types

    $.get("page/test.thml", function(html){
        $("#iframe").contents().find("html").html(html);
    },'html')

test.html包含css样式表。

但我得到Resource interpreted as Stylesheet but transferred with MIME type text/html:

html加载但它缺少它的CSS样式。我试图将css文件内容粘贴到html文件本身,但这并没有解决问题。

如何在加载html时显示css?

2 个答案:

答案 0 :(得分:0)

请找到以下解决方案。

<script type="text/javascript">
        $(document).ready(function () {
            // Your HTML Physical file path here// Note: style should have text/css attribute.
            $("#result").load("YourHTML.html", function () {
                alert($("#result").html()); // This is your HTML
            });
        });

    </script>

答案 1 :(得分:0)

试试这个:

$(document).ready(function () {
  $("#result").load("file.html");
});

它将自动加载包含css样式的html(带有嵌入式CSS的HTML)。但是如果你以正确的方式在html文件中设置css文件(Linked CSS case)的映射地址,那就没问题了。