我有一个.html,它是
a.html
<script>
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
我想打印a.html中包含的内容,而按钮位于b.html中
b.html
<a href="#" onclick="printContent("printJS")">Print</a>
如何将函数传递给其他文件?
谢谢
最佳答案
将您的函数提取到单独的 *.js 文件中,并将该文件包含在两个 html 文件中。
<script src="myscripts.js"></script>
关于javascript - JS : Call print function from other file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44090456/