亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

編輯,保存,自修改HTML文檔; 格式生成的HTML,JavaScript

編輯,保存,自修改HTML文檔; 格式生成的HTML,JavaScript

慕村9548890 2019-08-14 16:02:23
編輯,保存,自修改HTML文檔; 格式生成的HTML,JavaScript錯誤:字符串轉義,格式化html,js由初始編輯生成,保存html,js例如,a)如果在本地瀏覽器中打開“saveFile.html”;b)輸入“abc” textarea;c)單擊save file按鈕;d)單擊Save在Save File對話框;e)file-*[date according to universal time].html保存到磁盤;f)file-*[date according to universal time].html在瀏覽器中打開;g)輸入“def” textarea;h)重復d),e),f);i)Bug:第二個結果file-*[date according to universal time].html顯示textarea包含“abc def”文本內容; button 沒有顯示在html:// at rendered `html` from second `file-*[date according to universal time].html`// `textarea` containing "abc def" displayed here , // `button` _not_ displayed ; following string displayed following `textarea`:');"console.log(clone);var file = new Blob([clone], {'type':'text/html'});a.href = URL.createObjectURL(file);a.download = 'file-' + new Date().getTime() + '.html';a.click();};在第26行生成,“saveFile.html”+ "var clone = '<!doctype html>'+ document.documentElement.outerHTML.replace(/<textarea>.*<.+textarea>/, '<textarea>'+document.getElementsByTagName('textarea')[0].value+'<\/textarea>');"
查看完整描述

2 回答

?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

我不確定是什么打破了第三代克隆,因此它導致js信息輸出到頁面,但是使用實際文檔對象來克隆/操作原始文件并輸出其內容可能會更好Blob對象的字符串。例如,我使用您的基本saveFile.html進行了測試,并進行了以下更改:


//remove original clone var and replace with:

var clone = document.cloneNode(true);


// grab textarea elements from both original document and clone:

var doc_input = document.getElementsByTagName("textarea")[0];

var clone_input = clone.getElementsByTagName("textarea")[0];


// set clone textarea's innerHTML to current textarea value:

clone_input.innerHTML = doc_input.value;


// use outerHTML of clone.documentElement to get string for Blob

var clone_string = [clone.documentElement.outerHTML];

var file = new Blob([clone_string], {"type":"text/html"});

我看到的唯一缺點是:


這可能很難擴展到更通用的框架,用于生成當前加載的HTML頁面狀態的“實時HTML文件”(盡管它不應該比您的示例方法更復雜)。


返回的字符串clone.documentElement.outerHTML似乎將文檔類型聲明放到一個簡單元素中,以便:


不在輸出字符串中。你可以使用類似的東西:


var clone_string = ["<!doctype html>" + clone.documentElement.outerHTML];

作為一種解決方法?;蛘?,對于更強大的東西:


var doc_doctype = new XMLSerializer().serializeToString(document.doctype);


var clone_string = [doc_doctype + clone.documentElement.outerHTML];


查看完整回答
反對 回復 2019-08-14
  • 2 回答
  • 0 關注
  • 661 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號