我是php代码的新手,我已经创建了一个打印按钮,但它显示了整个页面的内容。我想创建一个打印预览,只为表单的内容打印。所以我需要怎么做,请有人帮我....这是我的代码。
储备.php
<?php include('header_user.php');?>
<div id="container">
<div id="content">
<div id="contentleft">
<div class="reserve-form">
<h1>Make Reserve</h1>
<form action="reservation.inc.php" method="POST">
<!--username-->
<label for="uname"><b>Username</b></label>
<input type="text" name="uid" placeholder="Your username" required="">
<!--username-->
</br>
<!--person-->
<label for="hperson"><b>Person</b></label>
<select id="person" name="person">
<option selected hidden>How many person?</option>
<option value="1 Person">1 Person</option>
<option value="2 Person">2 Person</option>
<option value="3 Person">3 Person</option>
<option value="4 Person">4 Person</option>
<option value="5 Person">5 Person</option>
</select>
<!--person-->
</br>
<!--date-->
<label for="wdate"><b>Date</b></label>
<input type="text" name="bookdate" placeholder="dd-MM-yy" required="">
<!--date-->
</br>
<!--time-->
<label for="wtime"><b>Time</b></label>
<input type="text" name="booktime" placeholder="0.00pm" required="">
<!--time-->
</br>
<!--Select Table-->
<label for="rtable"><b>Table No</b></label>
<select id="table" name="booktable">
<option selected hidden>Choose your table</option>
<option value="T1">T1</option>
<option value="T2">T2</option>
<option value="T3">T3</option>
<option value="T4">T4</option>
<option value="T5">T5</option>
</select>
<!--end select-->
<button type="submit" name="confirm" class="loginbtn">Confirm</button>
<a class="print_btn" href="" onclick="window.print();">Print</a>
</form>
</div>
</div><!--contentleft-->
<?php include('sidebar.php');?>
</div><!--content-->
</div><!--container-->
<?php include('footer_user.php');?>
您可以使用CSS3媒体标签解决此问题。给出您不想显示HTML类的部分,例如" No-Print",然后在CSS中添加媒体打印功能:
@media print {
.no-print {
display: none;
}
}