如何通过window.print()打印页面的某个特定部分 [英] How to print some specific part of a page via window.print()
本文介绍了如何通过window.print()打印页面的某个特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用php mysql的表单。所以在我的页面中有一个表格,下面我以表格格式显示了这个表格的数据。现在我只想打印表格结构,这就是为什么我只是打印一个PRINT按钮:
i'm working on a form in php mysql. so in my page there is a form and below that i shown the data of that form in table format.now i want to print only the table structure thats why i just made a PRINT button as:
<span style="float:right;"><a href="javascript:window.print()" type="button" class="btn">PRINT</a></span>
但它会打印整个页面的表格字段和表格,我只想要打印表格。
这里是我的整个页面的表格设计:
but it will print the whole page with form field and table and i just want the tableto print. Here is the design of my whole page with form and table:
<html>
<head></head>
<body>
<div class="container">
<form class="form-horizontal" action="" method="post" name="userform1" id="company-form" enctype="multipart/form-data">
<?php if($_GET[id]){?>
<fieldset>
<legend>Add Company</legend>
<div class="control-group">
<label class="control-label">Company Name</label>
<div class="controls">
<input type="text" name="company" id="company" value="<?php echo $selup['company']?>">
</div>
</div>
<div class="control-group">another field</div>
<div class="control-group">another field</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit" id="submit" value="Submit">Submit</button>
</div>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td>S.No.</td>
<td>Company Name</td>
<td>Type</td>
<td>Action</td>
</tr>
<?php
// to print the records
$select = "select * from company where type='Miscellaneous'";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td><?php echo $value[id];?></td>
<td><?php echo $value[company ];?></td>
<td><?php echo $value[type];?></td>
<!--<td> </td>-->
<?php /*?><td><?php echo $value[amount];?></td>
<td><?php echo $value[date];?></td><?php */?>
<td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $value[id];?>&cmd=edit"><i class="icon-edit"></i></a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $value[id];?>&cmd=delete" onclick="return confirm('Are you sure you want to delete <?php echo $value[customer];?>?')"><i class="icon-trash"></i></a></td>
</tr><?php }?>
</tbody>
</table>
</fieldset>
<form>
</div>
</body>
所以我只想打印表格而不是整个页面。
so i just want to print the table not whole page.
推荐答案
使用css隐藏不想打印的元素:
Use css to hide elements you don't want to print:
@media print {
.control-group {
display: none;
}
}
这篇关于如何通过window.print()打印页面的某个特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文