Javascript打印功能不打印表单元素的变化

时间:2014-01-06 07:42:46

标签: javascript forms printing

我有一个类似于下面的HTML表单:

    <div id="print">
        <h2>I am header</h2>
        Name : <input type="text" />
        College : B Borooah College
        <select>
            <option>Student</option>
            <option>Staff</option>
        </select>  
     <div>
<input type="button" value="PRINT" onclick="PrintContent()" />

还有一个javascript函数可以使用#print打印内容:

function PrintContent() 
{

    var DocumentContainer = document.getElementById('print');
    var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');


    WindowObject.document.writeln('<!DOCTYPE html>');
    WindowObject.document.writeln('<html><head><title></title>');
    WindowObject.document.writeln('</head><body>')

    WindowObject.document.writeln(DocumentContainer.innerHTML);

    WindowObject.document.writeln('</body></html>');

    WindowObject.document.close();
    WindowObject.focus();
    WindowObject.print();
    WindowObject.close();
}

当我点击print按钮时,它会打印默认表单,而不是我添加name feld或更改select drop down的表单。如何打印输入/更改的值?

1 个答案:

答案 0 :(得分:1)

如果你使用jQuery,也许这会有所帮助:

http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/Sample/

干杯