我有代码在单击按钮打印窗口打开后打印选定的 div 区域但问题是当我在文本框中输入内容然后单击按钮时文本框值从页面中消失并且文本框值也没有出现在打印中窗户?
<script>
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
<div id="printableArea">
<input type="text" >
</div>
<input type="button" onclick="printDiv('printableArea')" value="print a div!" />