In the previous article "Teach everyone to declare variables in different ways in JavaScript", I introduced you how to declare variables in different ways in JavaScript. Friends who are interested can learn about it. ~
The main content of this article is to teach you how to use JavaScript to print the content of div elements!
So to print the content of the div in JavaScript, we need to sort out the implementation ideas:
First store the content of the div in a JavaScript variable; then click the print button to extract the HTML div element; then create a JavaScript pop-up window and write the extracted content of the HTML div element into the pop-up window; and finally print the window using the JavaScript window print command.
Below we will implement it in two ways:
The first method: This example uses the JavaScript window print command to print the content of the div element
The effect before clicking the button is as follows:
Then we click the "Click to Print" button, and the following picture appears:
Second method: This example uses the JavaScript window print command to print the content of the div element
The effect before clicking the button is as follows:
The effect after clicking the "Click to Print" button is as follows:
Finally, I would like to recommend "JavaScript Basic Tutorial》~Welcome everyone to learn~
The above is the detailed content of Detailed explanation of how to use JavaScript to print the content of div elements. For more information, please follow other related articles on the PHP Chinese website!