html頁面局部打印


首先要把要打印的內容放在一個div里:我要打印的都放進id為:information1里面。

<div id="information1">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div id="info" class="x_content">

                                <img src="/qr/qrcode?content=${qrid}"/>

                                <h3>票類型:${ticktype}</h3>
                                <h3>票價格:${price}元</h3>

                            </div>

                        </div>
                    </div>
                    </div>

然后寫個script

<script type=text/javascript>

        function printdata() {

            window.document.body.innerHTML=window.document.getElementById("information1").innerHTML;
            window.print();

        }
</script>

最后再用一個按鈕 onclick這個方法

<input type="button"  class="btn btn-primary" value="打印" onclick="printdata()"/>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM