Javascript 如何使用java脚本在单击按钮时下载PDF格式的刀片页面?
我尝试了这个,但没有得到输出Javascript 如何使用java脚本在单击按钮时下载PDF格式的刀片页面?,javascript,node.js,angularjs,laravel,Javascript,Node.js,Angularjs,Laravel,我尝试了这个,但没有得到输出 .... .... 函数printDiv() { var divToPrint=document.getElementById('DivIdToPrint'); var newWin=window.open(“”,'Print-window'); newWin.document.open(); newWin.document.write(“”链接您使用的css“”+divToPrint.innerHTML+“”); newWin.document.close();
....
....
函数printDiv()
{
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open(“”,'Print-window');
newWin.document.open();
newWin.document.write(“”链接您使用的css“”+divToPrint.innerHTML+“”);
newWin.document.close();
setTimeout(函数(){newWin.close();},10);
}
什么是$(elId).pdf()代码>尝试此e1Id是需要下载的div的名称
function downloadInnerHtml(filename, elId) {
var elHtml = $(elId).pdf();
var link = document.createElement('a');
var mimeType = mimeType/'pdf';
link.setAttribute('download', filename);
link.setAttribute('href','data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
$(document).ready(function () {
$('#download').click(function () {
downloadInnerHtml(fileName, 'table4');
});
});
<a href="#" class="btn btn-primary" onclick='printDiv();'>Download Resume</a>
<div class="section-body" id="DivIdToPrint">
....
....
</div>
<script>
function printDiv()
{
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open('','Print-Window');
newWin.document.open();
newWin.document.write('<html><head> 'link your used css'</head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
newWin.document.close();
setTimeout(function(){ newWin.close(); }, 10);
}
</script>