我正在阅读一个HTML模板并将其添加到div(我已经设置了runat =' server')来自服务器端代码。这将在页面上呈现并完美显示HTML。现在,我更改了客户端上呈现的HTML中的文本,并希望在服务器端读取更新的文本(div中的完整HTML)以更新模板。所以我点了一个隐藏字段并在点击保存按钮时保存更新的div这样的HTML。
$('#btnSaveTemplate').click(function () {
$('#UpdatedEmailTemplate').val($('#divEmailBody').html());
});
HTML模板:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>
<strong><u>Database Decommission Notice – IMPORTANT NOTIFICATION</u></strong>
</p>
<p>
<strong>FOLLOWING DATABASE(S) ARE SCHEDULED TO BE DECOMMISSIONED in 4 WEEKS from {SentDate};</strong>
</p>
<p>
<strong>Why have you received this email?</strong>
</p>
<p>
You are receiving this email as because you are an ITAO/ITAO delegate/CSM/CSM-1/key technical contact for database(s) that are scheduled to be decommissioned by 30. Below are the applications you have been identified.
</p>
</body>
</html>
&#13;
问题是当我尝试在点击保存时在隐藏字段中保存更改的html时,它给出了如下内容。 (这是$(&#39; #divEmailBody&#39;)。html()方法的输出。
\n\n\n <title></title>\n\n\n <p>\n <strong>\n <img style=\"width: 744px; height: 141px;\" alt=\"\" src=\"http://nyccgdbb0004.us.db.com/images/emailImmediateActionRequired.png\" border=\"0\">\n </strong>\n </p>\n <p>\n <strong><u>Database Decommission Notice – IMPORTANT NOTIFICATION</u></strong>\n </p>\n <p align=\"center\" class=\"MsoNormal\" style=\"margin: 0in 0.5in 6pt 0in; text-align: center;\">\n <b>\n <i>\n <u>\n <span lang=\"EN-GB\" style=\"color: rgb(192, 0, 0); font-size: 14pt;\">Do not ignore this message</span>\n </u>\n </i>\n </b>\n </p>\n <p>\n <strong>FOLLOWING DATABASE(S) ARE SCHEDULED TO BE DECOMMISSIONED in 4 WEEKS from 1/23/2017;</strong>\n </p>\n \n <p>\n <strong>Why have you received this email?</strong>\n </p>\n <p>\n <a title=\"\" class=\"editableText editable editable-pre-wrapped editable-click editable-unsaved\" href=\"#\" data-original-title=\"\" data-title=\"Update Text\" data-type=\"textarea\">You are receiving this email as because you are an ITAO/ITAO delegate/CSM/CSM-1/key technical contact for database(s) that are scheduled to be decommissioned by 30. Below are the applications you have been identified.test</a>\n </p>\n\n\n\n"
如何阅读完整的HTML?
答案 0 :(得分:1)
如果是模板,则不要将其添加到任何html元素,例如div ..请改用脚本标记。
<script id="UpdatedEmailTemplate" type="text/x-template">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>
<strong><u>Database Decommission Notice – IMPORTANT NOTIFICATION</u></strong>
</p>
</body>
</html>
</script>
如果您将模板附加到div,它不会保持原样,浏览器会自行调整以使页面成为有效的html。在页面中你不能有两个html标签,所以浏览器会自动删除其他标签。身体也一样。 HTML永远不会抛出错误,但它自己修复错误..有时修复与我们想要的不一样。那就是为什么它的imp有有效的html
答案 1 :(得分:0)
使用Javascript
var html = document.getElementsByTagName('html')[0];
var text = '<html>' + html.innerHTML + '</html/>';
使用jQuery:
var text = '<html>' + $('html').html() + '</html/>';