如何使用window.print在我的结果中打印单个行,就像在我像这样打印添加的 anchor 标签中那样,它将我要打印的表中的所有行都以单独方式打印
最佳答案
根据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/