我在PHP页面中有6张图片。 每个图像下方都有一个名为print的按钮。
现在如何将PHP
或Javascript
中的命令发送到按钮,以便在单击时打印窗口只有相应的图像(不是整个HTML)
我的按钮:
<button type='print'>Print<\button>
答案 0 :(得分:0)
你可以试试这种方式
<script type="text/javascript">
function ImagetoPrint(source) {
return "<html><head><script>function step1(){\n" +
"setTimeout('step2()', 10);}\n" +
"function step2(){window.print();window.close()}\n" +
"</scri" + "pt></head><body onload='step1()'>\n" +
"<img src='" + source + "' /></body></html>";
}
function PrintImage(source) {
Pagelink = "about:blank";
var pwa = window.open(Pagelink, "_new");
pwa.document.open();
pwa.document.write(ImagetoPrint(source));
pwa.document.close();
}
<a href="#" onclick="PrintImage('YOUR_IMAGE_PATH_HERE.JPG'); return false;">PRINT</a>
答案 1 :(得分:0)
您可以使用
等JS库http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/
$('img#some_id').printElement();