为什么只打印一次?请给我解决方案 [英] Why does it print only one time? Please give me solution

查看:130
本文介绍了为什么只打印一次?请给我解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < HTML> 
< head>
< script type =text / javascript>
函数printpage()
{document。 getElementById('print')。style.display ='none';
window.print()
}
< / script>
< / head>
< body>
< td align =center>
< input name =printtype =submitid =printvalue =PRINTonclick =printpage()/>
< / td>
< / body>
< / html>

当我点击时,它会打开一个打印窗口。
一旦我关闭了打印窗口并再次打开,然后点击打印,无需重新加载,那么它将不起作用。

解决方案

printpage()中删除 document.getElementById('print')。style.display ='none'; c> function。

在上述情况下,该按钮对另一个点击事件是可见的,但是当您打印文档时,该按钮将显示在打印文档上。为了防止打印打印按钮,您需要使用

/www.w3.org/TR/css3-mediaqueries/rel =nofollow> css媒体查询 @media print



在您的extrernal样式表中添加以下内容,或者在< head> <$ c $中添加< style> / code>标签的HTML页面:

  @media print {
.noprint {display:none; }
}

并添加 .noprint
$ b

 < input name =printclass =noprinttype =submitid = printvalue =PRINTonclick =printpage()/> 

SEE DEMO



它将在不打印按钮的情况下打印文档,并且您的按钮对于第二个时间点击: - )



编辑: GIVEN BELOW:

 <!DOCTYPE html> 
< html>
< head>

< meta charset = utf-8 />
< title> JS Bin< / title>

<! - 您的样式表(CSS) - >
< style type =text / css>
@media print {
.noprint {display:none; }
}
< / style>

<! - 您的Javascript功能 - >
< script>
函数printpage(){
window.print();
}
< / script>

< / head>
< body>

<! - - 你的身体 - >
< p>仅限此文字将会列印< / p>

<! - 您的按钮 - >
< input class =noprinttype =buttonvalue =PRINTonclick =printpage()/>

< / body>
< / html>

请参阅上面的代码


<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>

When I click, it will open a print window. Once I close print window and open it again and then click on print, without reloading, then it will not work.

解决方案

Remove document.getElementById('print').style.display='none'; from your printpage() function.

In the above case the button will be visible for another click event but when you will print the document, the button will be shown on printed document. Am I right?

To prevent printing the print button you need to use css media queries @media print

Add following in your extrernal stylesheet OR in <style> tag inside a <head> tag of the HTML page:

 @media print {    
     .noprint { display: none; }
 }​

and add .noprint class on

<input  name="print" class="noprint" type="submit" id="print" value="PRINT" onclick="printpage()" />

SEE DEMO

It will print the document without printing the button and your button will also be visible for the second time click :-)

EDITED:

USE HTML AS GIVEN BELOW:

<!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>

SEE ABOVE CODE IN ACTION

这篇关于为什么只打印一次?请给我解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆