我是初学者。我使用此代码将<div>
内容导出到html文件,但转换器文件没有<html></html>
,<body></body>
,<head></head>
。请教我如何将此代码添加到导出文件?谢谢
HTML代码:
<div id="main"></div>
<script type="text/javascript">
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'main','text/html');
});
</script>
JS代码:
function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.createElement('a');
mimeType = mimeType || 'text/plain';
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
var fileName = 'Filename'+'.html';