javascript - 我怎样才能制作打印报告的打印按钮?

标签 javascript php

我正在做一个项目,但我的问题是我不知道如何制作打印按钮来打印我的报告..报告在表格中..有人可以帮助我吗一个?我的问题是如何添加打印按钮?

这是我用于查看特定记录的代码

<?php
    include_once 'dbconfig.php';
    $username = isset($_GET['username']) ? $_GET['username'] : '';
    $password = isset($_GET['password']) ? $_GET['password'] : '';
    $province = isset($_GET['province']) ? $_GET['province'] : '';

    if(isset($_GET['user_id']))
    {
        $user_id = $_GET['user_id'];
        extract($crud->getID($user_id));
    }
?>

<body>
<div id="Survey-view">
    <div id="header">
    </div>

    <p><strong>INFORMATION</strong></p>
        <hr />
            <div id="main-frame">
                <table id="information-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Username</th>
                            <th>Password</th>
                            <th>Province</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $password; ?></td>
                            <td><?php echo $province; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div>
        <br />
    <br />
    <p><strong>ASP</strong></p>
        <hr />
            <div id="asp">
                <table id="asp-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Date Survey</th>
                            <th>Date Submitted</th>
                            <th>Date Approved</th>
                            <th>Date Recv'd by Region</th>
                            <th>Date Recv'd by DARPO</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div><!-- End of asp-->
        <br />
    <br />
    <p><strong>DENR/DARPO</strong></p>
        <hr />
            <div id="denrdarpo">
                <table id="denrdarpo-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Date Survey</th>
                            <th>Date Submitted</th>
                            <th>Date Approved</th>
                            <th>Date Recv'd by Region</th>
                            <th>Date Recv'd by DARPO</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div><!--End of denrdarpo-->
        <br />
    <br />
    <p><strong>OTHERS</strong></p>
    <hr />
    <div id="others">
        <table id="others-content" cellspacing="0">
            <tr>
                <td>Project Number</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Module Number</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Fund Year</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>LAD Target</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Land Category</td>
                <td><select disabled>
                        <option><?php echo $username; ?></option>
                    </select></td>
                <td>LAnd Type</td>
                <td><select disabled>
                        <option><?php echo $username; ?></option>
                    </select></td>
            </tr>
            <tr>
                <td>Date Reported</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Date Suspended</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Date Completed</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Number of Lots</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Station</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Contractor</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Agency</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Cert 40</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
        </table>
    </div>
</div>
</body>

最佳答案

每次我需要这样做时,我都会转到我的旧 Gmail 帐户,打印一页,然后查看源代码,因为我懒得记住这些功能。

Google 就是这样做的。

<script type="text/javascript">// <![CDATA[
document.body.onload=function(){document.body.offsetHeight;window.print()};
// ]]></script>

您可以轻松地将其附加到按钮,而不是在加载时执行。

<button onclick="document.body.offsetHeight;window.print();">Print</button>

Here's a working example.

这个将从打印页面上删除按钮:

<button onclick="this.style.display='none';document.body.offsetHeight;window.print();this.style.display='inline';">Print</button>

And another example.

关于javascript - 我怎样才能制作打印报告的打印按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878858/

相关文章:

php - 使用 PHP 屏蔽图像生成 CGI 脚本的 URL

php - 发送数据到php数据库

javascript - jquery text() 不比较字符串

javascript - 如何从firestore获取数据到谷歌云功能?

PHP 使用字符串作为运算符

php - 如何使用简单的格式制作zf2输出错误?

php - 我怎样才能使这个 mysqli 查询在 PHP 中运行得更快?

javascript - 处理仅适用于特定内容的 Javascript 事件

javascript - Javascript 中的对象与数组就像 Python 的字典与列表?

javascript - 基于容器元素在 AngularJS 指令内自动调整 SVG 大小