使用Windows.print()..打印表单的某些字段。

时间:2014-01-24 03:56:00

标签: javascript php jquery html printing

我有一个从外部卡读取数据的脚本我在页面上有两个选项从卡中读取数据并在我点击“发送到打印机”时显示另一个是“发送到打印机”选项应该只打印必填字段。代码是

<body>
<br>
<div align="center">
<input type="button" value="Read myKad" id="btnRead" class="btn btn-success"><img src="loading.gif" id="loading" style="display:none">  

<script language="javascript">
if (window.print) {
document.write('<input type="button" value="Sent to Printer" id="btnRead" class="btn btn-warning" onClick="window.print()">');
}
</script>
<span id="msg"></span>
</div>
<hr/>
<span id="holder"></span>
</body>
<script>
$(document).ready(function(){
$("#btnRead").click(function(){
$("#imgpp").html("Please wait. Reading Cherry ..... ");
$("#loading").show();
$.ajax({
url: "read.php",
success: function(response){
//$("#imgpp").attr("src","http://192.168.0.4/mykadreader/sample/mypic.jpg?x=<?PHP echo date("Ymdhis"); ?>");
$("#holder").html(response);
$("#imgpp").html("Done Reading ");
$("#loading").hide()    ;   
$(".paper-table").tablecloth({
         theme: "paper",
         striped: true,
         sortable: true,
         condensed: false
       });
}
})
})
});
</script>

1 个答案:

答案 0 :(得分:3)

如果我理解正确,您只想打印部分页面。 您可以使用仅打印的CSS(即隐藏不需要的东西)来做到这一点。

即css文件将包含在:

<link rel="stylesheet" type="text/css" href="print.css" media="print" />

然后在此文件中,您可以在任何/所有不需要的元素上设置display:none。