텍스트 편집기를 만들고 있습니다. 이제 사용자가 버튼을 클릭하고 텍스트가 파일 (.txt)에 저장되는 지점에 갇혀 있습니다. div
에서 텍스트를 가져올 수 있지만 텍스트 편집기의 툴바에서 서식이 지정된 텍스트는 없습니다. - 굵게 , 이탤릭체 등 .. execommand
을 통해)div에서 형식이 지정된 텍스트를 가져 오는 방법은 무엇입니까?
실제로 어떻게 하는가?
편집
<div id="main">
<span>Content of #main div goes here</span>
</div>
<a href="#" id="downloadLink">Download the inner html of #main</a>
자바 스크립트 :
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.html'; // You can use the .txt extension if you want
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'main','text/html');
});
여기에 코드를 넣을 수 있습니까? – devendrant
wysiwyg 편집기를 사용하는 경우 편집기 설명서 –
을 읽으십시오. http://stackoverflow.com/help/how-to-ask.를 읽으십시오. – connexo