简体   繁体   English

如何将HTML文档添加到 <div></div> 通过JavaScript / JQuery?

[英]How to add a HTML document into a <div></div> via JavaScript/ JQuery?

How do I add an HTML doc into a <div></div> via JavaScript/ JQuery? 如何通过JavaScript / JQuery将HTML文档添加到<div></div>

This is what i have so far; 这是我到目前为止;

emailBodyInclude.html emailBodyInclude.html

<!DOCTYPE html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="css/imports/reset.css" type="text/css" />

    <script>
        // JavaScript
    </script>

</head>
<body>

    <p>Hello world! This is HTML5 Boilerplate.</p>

</body>
</html>

Using JavaScript/ JQuery, how can I go about removing from a HTML document any declarations of the form of: 使用JavaScript / JQuery,我如何从HTML文档中删除任何形式的声明:

<!DOCTYPE html>
<html class="no-js">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head></head>
<body></body>

So that I be left with: 所以我留下来:

<link rel="stylesheet" href="css/imports/reset.css" type="text/css" />

<script>
    // JavaScript
</script>

<p>Hello world! This is HTML5 Boilerplate.</p>

so that I can safely insert what remains into a <div></div> 这样我就可以安全地将剩余的内容插入到<div></div>

Thank you all in advance. 谢谢大家。

UPDATE: 更新:

emailBodyInclude.html is a String of HTML mail retrieved from a provider, like Yahoo, for example. emailBodyInclude.html是从提供商(例如Yahoo)检索的HTML邮件的字符串。 It is dynamic, and there is no way to tell what the syntax will look like. 它是动态的,没有办法说出语法是什么样的。 I would like to include this html document inside another. 我想把这个HTML文档包含在另一个中。 Inside a <div class="htmlMail"></div> <div class="htmlMail"></div>

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="../../baseCSS/bootStrap/bootstrap.min.css">
</head>
<body>
    <div class="header">This is a HTML email</div>
    <div class="htmlMail"></div>
</body>
</html>

您可以使用此负载http://api.jquery.com/load/

$('.htmlMail').empty().load('emailBodyInclude.html');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM