我有这个示例html内容的字段 我需要打印所有内容,包括输入值并将其显示在示例预览中。 我试过这个脚本来触发打印:如何从打印预览中使用jQuery/javascript获取输入值
虽然示例打印工作正常,但输入值不显示。我怎样才能做到这一点?我应该使用html()函数以外的其他选择吗?
function PrintPreview() {
printWindow = window.open("", "", "location=1,status=1,scrollbars=1,width=650,height=600");
printWindow.document.write($('#mainbody').html());
printWindow.document.close();
printWindow.focus();
}
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<div id="mainbody">
Last Name
<input type="text" id="lname" name="lname">First Name
<input type="text" id="fname" name="fname">Middle Name
<input type="text" id="mname" name="mname">
</div>
<input type="button" onclick="PrintPreview();" value="Print Preview" />
Thanks !.这工作! – Jarich
另外给div一个类,并隐藏除使用打印CSS之外的所有东西 - 然后你不需要打开弹出框 – mplungjan