給指定div區(qū)域打印功能

我有一個(gè)這樣的需要打印表格,但是表格數(shù)據(jù)因數(shù)據(jù)太多數(shù)據(jù)顯示不全,該功能是我很頭疼,按需求是找到一個(gè)給指定區(qū)域打印表格的數(shù)據(jù)區(qū)域,因此引用了一個(gè)叫jquery.pint.js的一個(gè)打印插件,并做此記錄。希望能幫到你?( ?? ·? ? ?)

一、引用jquery.pint.js插件
首先下載jquery.print.js
http://www.jq22.com/demo/jQueryPrint201709042243/jQuery.print.js

<script src="js/jquery-3.3.1.js"></script>
<script src="js/jQuery.print.js"></script>

二、代碼塊
寫(xiě)一個(gè)按鈕加入點(diǎn)擊事件,再給你要打印的區(qū)域加一個(gè)id

<div>
    <button class="print-link no-print" onclick="printele()">打印</button>

    <div id="ele2">
      <div>
        <div style="width: 100px;height:300px;background: paleturquoise;">
           <table width="100%" cellpadding="10" align="center" cellspacing="2" border="1" bordercolor="#ccc" style="height: 400px;">
              ......
           </table>
        </div>
      </div>
   </div>
</div>

三、事件塊

<script type='text/javascript'>
    //觸發(fā)printele點(diǎn)擊事件
    function printele() {
      $.print("#ele2");
    }
</script>

四、查看效果

沒(méi)點(diǎn)擊打印前.png
點(diǎn)擊打印后.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容