<head>
<style media=print>
table{display:none;}
.print{display:block;}
</style>
</head>
<body>
<table id=t1>...</table>
<table id=t2>...</table>
<table id=t3>...</table>
<input type=button value="print t2" onclick="p('t2')">
</body>
<script>
var table = null;//打印的table
var class = null;//保存打印table的样式
function p(tid){
table = document.getElementById(tid);
window.print();
}
window.onbeforeprint=function(){
if(table){class=table.className;table.className="print";}
}
window.onafterprint=function(){
if(table){table.className=class;table=null;class=null;}
}
</script>
没有测试过,这样也许可以实现吧
<style media=print>
table{display:none;}
.print{display:block;}
</style>
</head>
<body>
<table id=t1>...</table>
<table id=t2>...</table>
<table id=t3>...</table>
<input type=button value="print t2" onclick="p('t2')">
</body>
<script>
var table = null;//打印的table
var class = null;//保存打印table的样式
function p(tid){
table = document.getElementById(tid);
window.print();
}
window.onbeforeprint=function(){
if(table){class=table.className;table.className="print";}
}
window.onafterprint=function(){
if(table){table.className=class;table=null;class=null;}
}
</script>
没有测试过,这样也许可以实现吧
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货