读书人

JS打印功能的,该怎么解决

发布时间: 2012-01-18 00:23:26 作者: rapoo

JS打印功能的
想把一上的部分容到一新的窗口上,再把新上的容直接打印出,打印完候新的窗口掉.
那位大哥例.不感!!!!!
如一面上的TABLE,DIV.到新上再打印.

[解决办法]
关注
[解决办法]

[解决办法]
你的需求太模糊,JS是肯定能办到的。问题是你哪些是固定的,哪些是动态的?既然是动态数据。那么为何不直接输出为javascript变量来处理?而要处理一个动态table?而且table不像DIV,涉及到单元格合并等处理。我给你写段代码,你参考一下。如果还解决不了。那你把你的需求再详细描述一遍:

<html>
<head>
<title> </title>
<script type= "text/javascript ">

function printNewWindow(tableObj, tdval){
newWindow = window.open( ' ', 'newWindow ', 'height=300,width=500,scrollbars=auto ');
if (newWindow != null){
var docbody = newWindow.document.createElement( "body ");
newWindow.document.appendChild(docbody);
docbody.innerHTML = tableObj.outerHTML;

var tablebody = newWindow.document.createElement( "tbody ");
docbody.getElementsByTagName( "table ")[0].appendChild(tablebody);

var aTr = newWindow.document.createElement( "tr ");
var aTd = newWindow.document.createElement( "td ");
aTd.innerHTML = tdval;
aTr.appendChild(aTd);
tablebody.appendChild(aTr);

newWindow.print();
newWindow.close();
}
}

</script>
</head>
<body>
<table id= "t1 ">
<tbody>
<tr> <td> 姓名 </td> </tr>
<tr> <td> 年 </td> </tr>
</tbody>
</table>
</table>
<table>
<tr>
<td> 校 </td>
<td>
<input type= "button " name= "Submit " value= "打印1 " onClick= "printNewWindow(document.getElementById( 't1 '),this.parentNode.previousSibling.innerHTML) "> </td>
</tr>
<tr>
<td> 性 </td>
<td>
<input type= "button " name= "Submit2 " value= "打印2 " onClick= "printNewWindow(document.getElementById( 't1 '),this.parentNode.previousSibling.innerHTML) "> </td>
</tr>
</table>

</body>
</html>

[解决办法]
通过设置display: none; 应该可以达到那样的效果.

看看:http://sunflowerbbs.oicp.net/posts/list/47.page
[解决办法]
学习

读书人网 >J2SE开发

热点推荐