打印功能自定义

时间:2019-04-08 16:33:13

标签: javascript html printing

我如何在新行中这样但在印刷中进行每一次新计算

enter image description here

现在打印看起来像enter image description here 我可以删除左下角的网站网址(这是实时服务器中的网址)吗? 还有日期(左上方)?

代码HTML:<button type="button" id="Print" onclick="printContent('result')" > Print</button>(结果为textarea id)。

JS中的代码:

function printContent(e) {
    var restorepage = document.body.innerHTML;
    var printcontent = document.getElementById(e).innerHTML;
    document.body.innerHTML = printcontent  ;
    window.print();
    document.body.innerHTML = restorepage;
}

1 个答案:

答案 0 :(得分:0)

//try some like this,

var printcontent = "";

var printcontent2 = "";

for (var x = 0; x <= 10; x++) {

 printcontent = "hi" + x;

console.log(printcontent);

printcontent2 = printcontent2 + printcontent + "<br>";


}
document.body.innerHTML = printcontent2;
window.print();