Home > Web Front-end > JS Tutorial > body text

JavaScript Document Object Model-DOM Operation Technology

黄舟
Release: 2017-01-20 14:48:50
Original
1356 people have browsed it

Dynamic Script

We can insert JavaScript code into the page by using the <script> element in the page. There are two ways: one is to reference an external js file through the src attribute, and the other is to use this element to include a piece of js code. The so-called dynamic script means that the script does not exist when the page is loaded. The script can be added dynamically by modifying the DOM at a certain time in the future. Just like manipulating HTML elements, there are two ways to create dynamic scripts: inserting external files and directly inserting JavaScript code. </script>

Dynamically loaded external JavaScript code can be executed immediately, such as the following code:

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "demo.js";
document.body.appendChild(script);
Copy after login

JavaScript Document Object Model-DOM Operation Technology

As you can see from the results in the above figure, the above code A

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template