Javascript 如何将此凭证打印为A4大小的纸张? 函数myFunction(){ window.print(); }

Javascript 如何将此凭证打印为A4大小的纸张? 函数myFunction(){ window.print(); },javascript,css,printing,Javascript,Css,Printing,但是我只需要打印我的表Tr,Tr从这里选择代码 函数myFunction() { var divToPrint=document.getElementById('IDOFDIVTOBPRINTED'); var newWin=window.open(“”,'Print-window'); newWin.document.open(); newWin.document.write(“”+divToPrint.innerHTML+“”); newWin.document.close(); setTi

但是我只需要打印我的表Tr,Tr从这里选择代码

函数myFunction()
{
var divToPrint=document.getElementById('IDOFDIVTOBPRINTED');
var newWin=window.open(“”,'Print-window');
newWin.document.open();
newWin.document.write(“”+divToPrint.innerHTML+“”);
newWin.document.close();
setTimeout(函数(){newWin.close();},10);
}
<script>
function myFunction() {


window.print();
}
</script>
<form >
<input type="submit" value="Submit">
</form>
function myFunction() 
{

  var divToPrint=document.getElementById('IdOfDivTobePrinted');

  var newWin=window.open('','Print-Window');

  newWin.document.open();

  newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');

  newWin.document.close();

  setTimeout(function(){newWin.close();},10);

}