【问题标题】:count how many times print function call in javascript计算在 javascript 中调用 print 函数的次数
【发布时间】:2014-08-31 18:20:52
【问题描述】:

我有以下代码

<?php
ob_start();
include '../connection.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Easy Installment Motorcycle Scheme Haripur</title>

以下代码打印此页面

<script type="text/javascript">
function printpage()
  {
  window.print();
  }
</script>
</head>

<body onload="printpage()">
<div style="width:500px; margin-left:50px">
<?php
$sSql="SELECT * FROM landing_page WHERE status='active'";
$result=mysqli_query($con,$sSql);
if(!$result){
    die(mysqli_error($con));
    }
$row=mysqli_fetch_array($result);

?>
<h2 style="text-align:center">Receipt For <?php echo $row['schemeName'];?></h2>

在下一行,我想获取收据号码,它将在任何使用 php javascript 或 html 调用 print 函数时自动生成

<h3>Receipt No: </h3>
<?php
$sSql="SELECT * FROM draw_date_time";
$result=mysqli_query($con,$sSql);
if(!$result){
    die(mysqli_error($con));
    }
$row=mysqli_fetch_array($result);
?>
<h3>Draw Date: <u><?php echo $row['date_of_draw'];?></u> &nbsp; Draw Time: <u><?php echo $row['time_of_draw'];?></u> &nbsp; Draw Place: <u><?php echo $row['draw_address'];?></u></h3>
<?php
$reg_number=$_POST['reg_number'];
$month=date('Y-m-d',strtotime($_POST['month']));
$sSql="SELECT *
FROM users u LEFT JOIN
     installments i
     ON u.id = i.fk_users_id
WHERE u.reg_number = '$reg_number' AND i.month='$month'
LIMIT 0 , 30";
$result=mysqli_query($con,$sSql);
if(!$result){
    die(mysqli_error($con));
    }
$row=mysqli_fetch_array($result);
?>
<h2>Memebership No: <u><?php echo ucfirst($row['reg_number']);?></u></h2>
<table width="500" border="1" style="text-align:left">
  <tr>
    <th scope="row">Memeber Name</th>
    <td><?php echo ucfirst($row['user_name']);?></td>
          <th scope="row">Father Name</th>
    <td><?php echo ucfirst($row['father_name']);?></td>
  </tr>
  <tr>
    <th scope="row">Phone No</th>
    <td><?php echo $row['phone'];?></td>
    <th scope="row">CNIC No</th>
    <td><?php echo $row['cnic'];?></td>
  </tr>
  <tr>
    <th scope="row">Address</th>
    <td><?php echo $row['address'];?></td>
    <th scope="row">Receiver Name & address</th>
    <td><?php echo $row['name_adrs_recvr'];?></td>
  </tr>
  <tr>
    <th scope="row">Prv Arrear</th>
    <td><?php echo $row['prv_arrear'];?></td>
    <th scope="row">Amount</th>
    <td><?php echo $row['amount'];?></td>
  </tr>
  <tr>
    <th scope="row">Total</th>
    <td><?php echo $row['total'];?></td>
    <th scope="row">Receive</th>
    <td><?php echo $row['receive'];?></td>
  </tr>
  <tr>
    <th scope="row">Arrear</th>
    <td><?php echo $row['arrear'];?></td>
    <th scope="row">Date Receive</th>
    <td><?php echo date('d-m-Y',strtotime($row['month']));?></td>
  </tr>
</table>
<?php
                $sql="SELECT * FROM landing_page WHERE status='active'";
                $result=mysqli_query($con, $sql);
                $row=mysqli_fetch_assoc($result);
                ?>
                <fieldset>
                <legend><img src="images/termsHead.png" style="float:right" /></legend>
                <p><img src="../images/<?php echo $row['image2'];?>" width="400" height="300" /></p>
                </fieldset>
</div>
</body>
</html>

请帮帮我。

【问题讨论】:

  • 你可以在javascript中创建一个全局var count并设置为0。然后每次调用printpage()时增加count。

标签: javascript php html


【解决方案1】:

定义一个用于计数的变量,每次打印页面时将其加一。

var printed = 0;
function printPage() {
    print(); // "window." isn't needed
    printed += 1; // Adds 1
    alert(printed); // Alerts you overall how many times
};

【讨论】:

  • 它不工作我想我问错了我正在编辑我的问题并向你展示整个代码。
猜你喜欢
  • 2021-06-10
  • 2018-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-19
  • 2023-01-11
  • 1970-01-01
相关资源
最近更新 更多