2017-01-23 81 views
1

我讀一個HTML模板,並將其添加到div的(我已經設置RUNAT =「服務器」)從服務器端代碼後面。這完美地呈現並在頁面上顯示HTML。現在,我更改客戶端呈現的HTML內的文本,並希望讀取服務器端的更新文本(div內的完整HTML)以更新模板。所以我已經採取了一個隱藏的領域,並保存點擊保存按鈕這樣的div更新的HTML。閱讀DIV內容USIG的jQuery跳過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>

的問題是,當我嘗試在隱藏字段保存更改的HTML在保存點擊,它給了我喜歡的內容如下。 (這是$( '#divEmailBody')輸出。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

DOM中的UpdatedEmailTemplate和divEmailBody在哪裏? –

+0

您的錯誤已經發生在您嘗試將_complete_ HTML文檔填充到div中的位置。這當然是無效的HTML,所以瀏覽器會放棄在這種情況下無法理解的元素。 – CBroe

回答

0

使用JavaScript

var html = document.getElementsByTagName('html')[0]; 
var text = '<html>' + html.innerHTML + '</html/>'; 

使用jQuery:

var text = '<html>' + $('html').html() + '</html/>'; 
1

如果是模板,那麼請不要將它添加到像格..使用腳本標籤,而不是任何HTML元素。

<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

相關問題