Javascript打印功能不打印表单元素更改

标签 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();
}

当我单击打印按钮时,它会打印默认表单,而不是我添加名称字段或更改选择下拉菜单的表单。我怎样才能打印我输入/更改的值?

最佳答案

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

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

干杯

关于Javascript打印功能不打印表单元素更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20945257/

相关文章:

javascript - 解除绑定(bind)点击事件后,jQuery 开/关方法不起作用

javascript - Mocha - 柴 karma "suite is not defined"

jQuery:我使用什么监听器来检查浏览器自动填充密码输入字段?

javascript - 将用户输入存储在数组中

css - 如果内容大于图像,如何正确调整 CSS 表单选择字段

javascript - jQuery $this + 兄弟元素调用不起作用

javascript - 理解 JavaScript 中的 OOP

C++:打印或计算一个标准库容器到控制台

html - 如何横向打印 HTML?

css - 在 Google Chrome 中为每个页面打印标题