http://xiangai.taobao.com
http://shop148612228.taobao.com

js局部打印

因为需要用到这个东西,所以很无耻的拾人牙慧,收在博客里了~

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">  
    function doPrint() {   
        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>
</head>
 
<body>
<p>1</p>
<p>2</p>
<!--startprint--><!--注意要加上html里star和end的这两个标记,之前没加,一直没效果,谁叫咱们菜呢~-->
<h1>打印标题</h1>
<p>打印内容~~</p>
<!--endprint-->
<button type="button" onclick="doPrint()">打印</button>
<p>1</p>
<p>2</p>
</body>
</html>

 原文地址:http://www.cnblogs.com/mofish/archive/2012/02/27/2370186.html

posted @ 2012-02-27 22:49  万事俱备就差个程序员  阅读(305)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏