<script> function printHtml(){ window.print(); } </script> <button onclick="printHtml();">打印</button>
<script> function appointprint(){ var newWindow=window.open("打印窗口","_blank"); var docStr=document.getElementById('appoint').innerHTML; newWindow.document.write(docStr); newWindow.print(); newWindow.close(); } </script> <button onclick="appointprint()">打印指定区域</button>
function printdiv(id) { var headhtml = "<html><head><title></title></head><body>"; var foothtml = "</body>"; // 获取div中的html内容 var newhtml = document.all.item(id).innerHTML; // 获取原来的窗口界面body的html内容,并保存起来 var oldhtml = document.body.innerHTML; // 给窗口界面重新赋值,赋自己拼接起来的html内容 document.body.innerHTML = headhtml + newhtml + foothtml; // 调用window.print方法打印新窗口 window.print(); // 将原来窗口body的html值回填展示 document.body.innerHTML = oldhtml; return false; }
Powered by codetiler.com