gpt4 book ai didi

javascript - 如何通过 JavaScript/JQuery 将 HTML 文档添加到
中?

转载 作者:可可西里 更新时间:2023-11-01 13:28:40 25 4
gpt4 key购买 nike

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

这就是我目前所拥有的;

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>

最佳答案

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

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

关于javascript - 如何通过 JavaScript/JQuery 将 HTML 文档添加到 <div></div> 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33602212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com