js实现打印

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script language="javascript">

function printdiv(printpage){

    var headstr="<html><head><title></title></head><body>";

    var footstr="</body>";

    var newstr=document.all.item(printpage).innerHTML;

    var oldstr=document.body.innerHTML;

    document.body.innerHTML=headstr+newstr+footstr;

    window.print();

    document.body.innerHTML=oldstr;

    return false;

}

</script>

<title>div print</title>

</head>

<body>

<input type="button" onClick="printdiv('div_print');" value=" 打印 ">

<div id="div_print">

<h1 style="Color:Red">被打印区域:www.phpernote.com</h1>

</div>

这块区域是打印不到的!

</body>

</html>

 

posted @ 2015-04-23 10:36  飞翔的小鸟11  阅读(143)  评论(0编辑  收藏  举报