html源码
<!DOCTYPE html><html><head><title></title></head><meta charset="utf-8"><script type="text/javascript">function my_print(){//直接调用浏览器打印功能bdhtml=window.document.body.innerHTML; //定义打印区域起始字符,根据这个截取网页局部内容sprnstr="<!--startprint-->"; //打印区域开始的标记eprnstr="<!--endprint-->"; //打印区域结束的标记 prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //还原网页内容window.document.body.innerHTML=prnhtml; //开始打印window.print();}</script><body><a href="#" onClick="my_print();" ><span> 打 印</span></a><br><!--startprint--><img src="test.jpg" style="height: 150px;width:150px"/><!--endprint--></body></html>
测试结果: