JS连接小票打印机

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" /> 
        <script src="http://cdn.outsiderla.me/js/jquery-1.6.4.min.js"></script>
 
        <style media=print type="text/css">
            .noprint{visibility:hidden}
        </style> 
    </head>
    <body>
        要打印的内容
        <p class="noprint">将不打印的代码放在这里。</p>
        <a href="#" class="print">打印</a>
 
        <hr/>
        <span id='div1'>把要打印的内容放这里</span>
        <p>所有内容</p>
        <div id="div2">div2的内容</div>
        <a href="#" id="print">打印</a>
        <script>
            $(function(){
                $('.print').click(function(){
                    window.print()
                })
                $('#print').click(function(){
                    document.body.innerHTML=document.getElementById('div1').innerHTML+'<br/>'+document.getElementById('div2').innerHTML;
                    window.print();
                })
 
            })
 
        </script>
    </body>
</html>
posted @ 2016-10-11 19:10  猴子1  阅读(1745)  评论(0编辑  收藏  举报