<html>
<head>
<script type="text/javascript">
function printpage()
{document. getElementById ('print').style.display='none';
window.print()
}
</script>
</head>
<body>
<td align="center">
<input name="print" type="submit" id="print" value="PRINT" onclick="printpage()" />
</td>
</body>
</html>
当我点击时,它会打开一个打印窗口。 一旦我关闭打印窗口并再次打开它然后单击打印,而不重新加载,它将无法工作。
最佳答案
删除 document.getElementById('print').style.display='none';
来自你的 printpage()
功能。
在上述情况下,按钮将在另一个点击事件中可见,但当您打印文档时,该按钮将显示在打印的文档上。我说得对吗?
防止打印print
您需要使用的按钮 css media queries @media print
在您的外部样式表或 <style>
中添加以下内容<head>
内的标签HTML页面的标签:
@media print {
.noprint { display: none; }
}
并添加.noprint
上课
<input name="print" class="noprint" type="submit" id="print" value="PRINT" onclick="printpage()" />
它将在不打印按钮的情况下打印文档,您的按钮也将在第二次点击时可见:-)
已编辑:
使用如下所示的 HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!-- Your Stylesheet (CSS) -->
<style type="text/css">
@media print {
.noprint { display: none; }
}
</style>
<!-- Your Javascript Function -->
<script>
function printpage() {
window.print();
}
</script>
</head>
<body>
<!-- Your Body -->
<p>Only This text will print</p>
<!-- Your Button -->
<input class="noprint" type="button" value="PRINT" onclick="printpage()" />
</body>
</html>
关于javascript - 为什么它只打印一次?请给我解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11738380/