我正在处理来自DIV标签的HTML导出选项,包括元素和属性
HTML:
<div id="master"><span class="classname">content goes here</span></div>
<span class="download" onclick="calldownload()">Download</span>
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 = 'output.html';
function calldownload(){
downloadInnerHtml(filename, 'master', 'text/html');
}
输出:
<span>Content goes here<span>
必填项:
<span class="classname">Content goes here<span>
提前致谢!
答案 0 :(得分:0)
你的HTML错了。 你写了:
jQuery(window).ready(function() {
jQuery(".shareaholic-share-button-container,.share-button-counter").css("opacity", "0");
});
而不是
<span="className">
答案 1 :(得分:0)
<div id="master"><span="classname">content goes here</span></div>
对于HTML,此行部分中的是不可理解的。你应该定义属性名称,如class,id,style等。
<div id="master"><span id="classname">content goes here</span></div>
<div id="master"><span class="classname">content goes here</span></div>
等...