天天看點

頁面有列印功能,去除列印按鈕

做了一個求職網站,有履歷列印功能,列印功能是實作了,但是列印的時候列印按鈕也會被列印出來。

  1. 解決方法如下:
<div class="preview_bottom" id="hide_btn">
    <div class="preview_btn">
        <input type="button" class="download btn" onclick="window.location.href='/user/download-resume'">
        <input type="button" class="print btn" onclick="beforePrint();window.print();afterPrint();">
    </div>
</div>
<script>
//-----  下面是列印控制語句  ----------
window.onbeforeprint=beforePrint;
window.onafterprint=afterPrint;
//列印之前隐藏不想列印出來的資訊
function beforePrint()
{
    var tag=document.getElementById('hide_btn'); 
    tag.style.display='none';

}
//列印之後将隐藏掉的資訊再顯示出來
function afterPrint()
{
    var tag=document.getElementById('hide_btn'); 
    tag.style.display='';
} 
</script>
           

供有需要的小夥伴參考。