简体   繁体   English

为什么我的打印不起作用?

[英]why my print doesn't work?

In this below program i am printing the contents of the div when i click the print button i am receiving an alert message printer error not available why it is so 在下面的程序中我打印div的内容当我点击打印按钮我收到一条警告消息打印机错误不可用为什么它是这样的

<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).text());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'my div', 'height=400,width=600');
        mywindow.document.write('<html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.document.close();
        mywindow.print();
        return true;
    }

</script>
</head>
<body>

<div id="mydiv">
    This will be printed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a quam at nibh adipiscing interdum. Nulla vitae accumsan ante. 
</div>


<input type="button" value="Print Div" onclick="PrintElem('#mydiv')" />

</body>
</html>

Because your physical printer is not physically plugged in or not correctly installed. 因为您的物理打印机没有物理插入或未正确安装。 The code is not wrong. 代码没有错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM