【发布时间】:2017-06-29 06:46:44
【问题描述】:
编辑内部 html 并保存。那就是下载它:
<script type="text/javascript" >
$(document).ready(function () {
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 = 'tags.txt';
$('.edit').click(function () {
$(this).hide();
$('#content').addClass('editable');
$('p').attr('contenteditable', 'true');
$('.save').show();
});
$('.save').click(function () {
$(this).hide();
$('#content').removeClass('editable');
$('p').removeAttr('contenteditable');
$('.edit').show();
downloadInnerHtml(fileName, 'content', 'text/plain');
});
});
</script>
【问题讨论】:
-
你的问题是什么?
-
它只适用于 chrome 而不是 firefox 如何让它在 firefox 中也能正常工作
-
在 Firefox 中发生了什么?有错误吗?
-
它不会下载
-
好的,请看我的回答。
标签: javascript jquery asp.net asp.net-mvc html