当前位置:首页 > 代码星空

JS打印尺寸和界面设置

时间:2024-12-27 23:47   浏览:364   发布部门:信息中心

<script>
        function printDiv(divId) {
            var printContents = document.getElementById(divId).innerHTML;
            var newWindow = window.open('', '', 'width=1000,height=800');
            newWindow.document.write('<html><head><title>打印</title>');
            newWindow.document.write('</head><body>');
            newWindow.document.write(printContents);
            newWindow.document.write('</body></html>');
            newWindow.document.close();
            newWindow.focus();
            newWindow.print();
            newWindow.close();
        }
    </script>

<div id="printableArea">
打印内容。
</div>

<button type="button" onclick="printDiv('printableArea')"   class="layui-btn" >打印</button>