如何在网页中插入打印表单的打印按钮 [英] How can I insert a Print button that prints a form in a webpage

查看:73
本文介绍了如何在网页中插入打印表单的打印按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,假设我在一个页面中有一个简单的表单,如下所示:

<p>东西</p></表单>

我想添加一个按钮,这样当用户点击它时,浏览器的打印对话框就会出现,我该怎么做?

我想打印表格,而不是页面.

解决方案

打印整页

尝试添加一个调用 window.print() 的按钮一个>

在页面中打印特定部分/容器

然后在HTML文件中,添加这个脚本代码

参考打印

;只有?

So, lets say I got a simple form inside a page like this:

<form style="text-align:center;">
    <p> STUFF </p>
</form>

I wanna add a button so when the user clicks on it the browser's Print dialog shows up, how can I do that?

Edit: I wanna print the form, not the page.

解决方案

Print the whole page

Try adding a button that calls window.print()

<input type="button" value="Print this page" onClick="window.print()">

Print a specific portion/container in a page

<div id="print-content">
 <form>

  <input type="button" onclick="printDiv('print-content')" value="print a div!"/>
</form>
</div>

then in the HTML file, add this script code

<script type="text/javascript">
    function printDiv(divName) {
        var printContents = document.getElementById(divName).innerHTML;
        w=window.open();
        w.document.write(printContents);
        w.print();
        w.close();
    }
</script>

Refer Print <div id="printarea"></div> only?

这篇关于如何在网页中插入打印表单的打印按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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