Home > Web Front-end > HTML Tutorial > How to embed js code in html

How to embed js code in html

王林
Release: 2021-01-12 10:57:50
forward
3560 people have browsed it

How to embed js code in html

How to embed javascript code in HTML pages

(Learning video sharing: html video tutorial)

<html> <body> 
<script type="text/javascript"> document.write("Hello World!"); </script> 
</body> </html>
Copy after login

above The code will produce this output in the HTML page:

Hello World!
Copy after login

Explanation of examples:

If you need to insert a piece of JavaScript into the HTML page, we need to use the <script> tag (and use the type attribute to Define scripting language). </p><p>In this way, <script type="text/javascript"> and </script> can tell the browser where JavaScript starts and ends.

<html> <body> 
<script type="text/javascript"> ... </script>
 </body> </html>
Copy after login

The document.write field is a standard JavaScript command used to write output to the page.

After entering the document.write command between , the browser will execute it as a JavaScript command. This way the browser will write "Hello World!" to the page.

<html> <body> 
<script type="text/javascript"> document.write("Hello World!"); </script>
 </body> </html>
Copy after login

Note: If we do not use the

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