Ie comes with Active controls, but Firefox does not. The Javascript dom method is used to print the text in the specified mark of the form. Therefore, you need to define the related labels and styles (such as the text size and font) for use ).
Copy codeThe Code is as follows: <script type = "text/javascript">
///***********************
/// Print the page of the specified region
/// Description: obj-get the tag ID through getElementById or other methods, and print the text in this obj
/// Date: 2009-8-7
Function startPrint (obj)
{
Var oWin = window. open ("", "_ blank ");
Var strPrint = "
StrPrint = strPrint + "<script type = \" text/javascript \ "> \ n ";
StrPrint = strPrint + "function printWin () \ n ";
StrPrint = strPrint + "{";
StrPrint = strPrint + "var oWin = window. open (\" \ ", \" _ blank \ "); \ n ";
StrPrint = strPrint + "oWin.doc ument. write (document. getElementById (\" content \ "). innerHTML); \ n ";
StrPrint = strPrint + "oWin. focus (); \ n ";
StrPrint = strPrint + "oWin.doc ument. close (); \ n ";
StrPrint = strPrint + "oWin. print () \ n ";
StrPrint = strPrint + "oWin. close () \ n ";
StrPrint = strPrint + "} \ n ";
StrPrint = strPrint + "<\/script> \ n ";
StrPrint = strPrint + "StrPrint = strPrint + "<div id = \" content \ "> \ n ";
StrPrint = strPrint + obj. innerHTML + "\ n ";
StrPrint = strPrint + "</div> \ n ";
StrPrint = strPrint + "StrPrint = strPrint + "<div style = 'text-align: Center'> <button onclick = 'printwin () 'style = 'padding-left: 4px; padding-right: 4px; '> Print </button> <button onclick = 'window. opener = null; window. close (); 'style = 'padding-left: 4px; padding-right: 4px; '> close </button> </div> \ n ";
OWin.doc ument. write (strPrint );
OWin. focus ();
OWin.doc ument. close ();
}
</Script>
<Button id = "btnPrint" onclick = "startPrint (document. getElementById ('content')"> print content </button>
<Div id = "content">
<Div style = "font-size: 12px; color: #333;">
Here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content
</Div>
</Div>
The following is the test code:Xmlns = "http://www.w3.org/1999/xhtml">
Print content
Here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content here is the print content