我有一个类似于下面的 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();
}
当我单击打印
按钮时,它会打印默认表单,而不是我添加名称
字段或更改选择下拉菜单的表单
。我怎样才能打印我输入/更改的值?
最佳答案
关于Javascript打印功能不打印表单元素更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20945257/