Recently did the Web page schedule printing, the Internet to find some information, and finally use the following method to achieve the functions I need. Place the table in the DIV tag where you want to print the schedule, and then specify the area you want to print, and finally call Window.print to print the specified content.
Sample code (some of the content in the code has been omitted)
Copy Code code as follows:
Function Preview () {
bdhtml = Window.document.body.innerHTML;
Sprnstr = "<!--startprint-->";
Eprnstr = "<!--endprint-->";
prnhtml = Bdhtml.substr (Bdhtml.indexof (SPRNSTR) + 17);
prnhtml = prnhtml.substring (0, Prnhtml.indexof (eprnstr));
Window.document.body.innerHTML = prnhtml;
Window.print ();
}
The above is the JavaScript code, the following is the HTML page code
Copy Code code as follows:
<div class= "Print" >
<input type= "button" value= "Print Timetable" onclick= "preview ()"/>
</div>
<div class= "Result" >
Schedule Query Results
</div>
<center> This section is printed below </center>
<!--startprint-->
<div class= "Timetable" >
<table id= "table1" class = "Tableresult" style= "Margin-left:auto;margin-right:auto"; >
<tr >
<th> </th>
<th> Monday </th>
<th> Tuesday </th>
<th> Wednesday </th>
<th> Thursday </th>
<th> Friday </th>
<th> Saturday </th>
<th> Sunday </th>
</tr>
<tr >
<th> 1, Section 2 </th>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
<td></td>
</tr>
<tr >
<th> 3, Section 4 </th>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
<td></td>
</tr>
<tr >
<th> 5, section 6 </th>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td> Information Technology <br> Digital Letters College <br>501 computer room <br> Bio-professional </td>
</tr>
<tr >
<th> 7, Section 8 </th>
<td></td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
University of <td> Information Technology <br> Digital College <br>501 computer room <br> Bio-professional </td>
<td></td>
<td></td>
</tr>
</table>
</div>
<!--endprint-->
<center> This section is printed above </center>