js生成txt文件


HTML CODE:

<div class="modal-footer">
     <a onfocus="this.blur();" id="createInvoteBtn" class="ipt-todo" href="javascript:void(0)">生成並導出Txt文件</a>
     <a onfocus="this.blur();" download="code.txt" id="createInvote" class="ipt-todo hide" >code</a>
</div>

 

Js CODE:

var isIE = (navigator.userAgent.indexOf('MSIE') >= 0);
if (isIE) {
     var strHTML = _txt;
     var winSave = window.open();
     winSave.document.open("text","utf-8");
     winSave.document.write(strHTML);
     winSave.document.execCommand("SaveAs",true,"code.txt");
     winSave.close();
} else {
     var elHtml = _txt;
     var mimeType =  'text/plain';
     $('#createInvote').attr('href', 'data:' + mimeType  +  ';charset=utf-8,' + encodeURIComponent(elHtml));
     document.getElementById('createInvote').click();
}

 

效果:

   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM