Javascript 打印函数不打印表单 elemnt 更改



我有一个类似于下面的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的表单。如何打印我输入/更改的值?

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

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

干杯

最新更新