如何使用window.print在我的结果中打印单个行

时间:2015-12-30 13:21:50

标签: javascript php

When Checkbox is Checked Expand Div

如何使用window.print在我的结果中打印单个行,只是在我添加的锚标记中,就像这个打印一样,它带来了我想要以个性化方式打印的表格中的所有行

1 个答案:

答案 0 :(得分:0)

根据print html through javascript / jquery,您可以使用以下代码:

function Print() {
  var docprint = window.open("about:blank", "_blank");//new page
  var oTable = document.getElementById("result_tbl").rows.item(0); //get the 1st row by a selector
  docprint.document.open();
  docprint.document.write('<html><head><title>Ashley Mattresses</title>'); //write HEAD section
  docprint.document.write('</head><body><center>'); //write BODY tag and center tag for printing
  docprint.document.write(oTable.innerHTML); //select the TR's HTML and add it to the new page
  docprint.document.write('</center></body></html>'); //close BODY tag
  docprint.document.close();
  docprint.print();
  docprint.close();
}

http://jsfiddle.net/v7CNG/77/