如何通过JavaScript / JQuery将HTML文档添加到<div></div>
?
这是我到目前为止所拥有的;
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>
使用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>
所以我留下来:
<link rel="stylesheet" href="css/imports/reset.css" type="text/css" />
<script>
// JavaScript
</script>
<p>Hello world! This is HTML5 Boilerplate.</p>
这样我就可以安全地将剩余的内容插入<div></div>
提前谢谢大家。
更新
emailBodyInclude.html是从提供商(例如Yahoo)检索的HTML邮件的字符串。它是动态的,没有办法说出语法是什么样的。我想把这个HTML文档包含在另一个中。在<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>
答案 0 :(得分:2)
您可以对此http://api.jquery.com/load/
使用加载$('.htmlMail').empty().load('emailBodyInclude.html');