js打印
<form id="WebForm1" method="post" name="myform" >
<table width="400" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>打印打印打印打印打印打印打印打印打印打印打印打印</td>
<td><input type="text" name="txt" id="txt" /></td>
</tr>
<tr>
<td>打印打印打印打印打印打印打印打印打印打印打印打印</td>
<td><input type="text" name="txt" id="txt" /></td>
</tr>
<tr>
<td>打印打印打印打印打印打印打印打印打印打印打印打印</td>
<td><input type="text" name="txt" id="txt" /></td>
</tr>
</table>
</form>
<div><input type="button" name="print" value="预览并打印" onclick=""> </div>
我想打印text文本框里面的内容。
window.print()试过了,它会连文本框一起打印。
------解决方案--------------------document.getElementById('WebForm1').print();
------解决方案--------------------可以增加打印样式隐藏输入框,参考:CSS media使用技巧
<style>
@media print/*用于打印时的样式,隐藏输入框*/
{
input{display:none}
}
</style>
<form id="WebForm1" method="post" name="myform" >
<table width="400" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>打印打印打印打印打印打印打印打印打印打印打印打印</td>
<td><input type="text" name="txt" id="txt" /></td>
</tr>
<tr>
<td>打印打印打印打印打印打印打印打印打印打印打印打印</td>
<td><input type="text" name="txt" id="txt" /></td>
</tr>
<tr>