<STYLE media="print">
#btnprint,#printdiv {
display: none
}
</STYLE>
使用<style>标签的media属性。详见
http://www.w3school.com.cn/tags/att_style_media.asp。
打印按钮:
<div id="printdiv"
style="position: absolute; width: 100px; height: 33px; top: 10px; left: 660px; background-color: orange; text-align: center; border: 1px solid black">
<input type=button id=btnprint value="【打印】" style="margin-top: 5px"
onclick="doPrint()">
</div>
function doPrint(){
window.print();
}
使【打印】按钮随页面滚动:
function movePrintBtn(){
document.all.printdiv.style.top = document.body.scrollTop + 10 + "px";
}
使用onscroll。
HTML 5 事件属性:
http://www.w3school.com.cn/html5/html5_ref_eventattributes.asp
<body onscroll="movePrintBtn()">