当前位置: 代码迷 >> Web前端 >> 打印网页局部的步骤
  详细解决方案

打印网页局部的步骤

热度:297   发布时间:2012-11-23 00:03:43.0
打印网页局部的方法

<input type="button" name="print" value="预览并打印" onclick="preview()">

<!--startprint-->

中间是你要打印的部分!一定记得

<!--endprint-->

?

<script language="Javascript">

function preview()

{

?? ?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>

  相关解决方案