[英]JavaScript WIndow Print - I want it to print a specific div
I have this nifty shopping helper at http://www.spacerock.com/shoppingplanner.php - click a meal and the ingredients appear in the shopinglist div. 我在http://www.spacerock.com/shoppingplanner.php上有这个漂亮的购物助手-单击一顿饭,食材就会出现在shopinglist div中。 I have the print window button at the top but it does not print that div.
我在顶部有“打印窗口”按钮,但它不打印该div。 How can I designate it to print that div?
如何指定它来打印该div? The code for the button is I know it's probably very simple;
按钮的代码是我知道的,它可能非常简单; I'm a jQuery person and need to learn PURE JS.
我是jQuery使用者,需要学习PURE JS。 Thanks in advance for your help and education.
在此先感谢您的帮助和教育。
Use This JS: 使用此JS:
to print specific DIV
with ID='content'
打印
ID='content'
特定DIV
<input style="width:75px" type="button" name="printreport" id="printreport" value="Print List" onclick="printpage()">
function printpage()
{
var originalContents = document.body.innerHTML;
var printReport = document.getElementById('content').innerHTML;
document.body.innerHTML = printReport;
window.print();
document.body.innerHTML = originalContents;
}
Hope this helps.. 希望这可以帮助..
You could try using the printThis Jquery plugin: 您可以尝试使用printThis Jquery插件:
$('SelectorToPrint').printThis();
JSFIDDLE https://jsfiddle.net/seadonk/df4tzcq5/ JSFIDDLE https://jsfiddle.net/seadonk/df4tzcq5/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.