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

时间:2010-03-25 05:27:07

标签: javascript html

在下面的程序中,当我点击打印按钮时,我正在打印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>

1 个答案:

答案 0 :(得分:6)

因为您的物理打印机没有物理插入或未正确安装。代码没错。