Basic application of javascript embedded and external linksThe js language can be completely placed in the html language But depending on the situation, it can be divided into embedded and external links. When there is less js code, you can directly use the embedded method to introduce javascript through the <script></script> tag and related attributes <!DOCTYPE html> <html> <script> document.write("<h1>This is a heading</h1>"); document.write("<p>This is a paragraph.</p>"); </script> <body> </body> </html> However, in large projects and when there are a lot of javascript codes, you need to use external links. When using external links, you need to create a new .js file first <!DOCTYPE html> <html> <script type="text/javascript" src="1245.js"> </script> <body> </body> </html> Put the javascript code you need to write in the 1245.js file Three ways to write JavaScript: inline, embedded, and externally linked1. InlineIn the attributes of the HTML tag, the execution is triggered by the behavior. (Rarely used) 2. EmbeddedWrap it in the HTML file using a script tag and it will execute automatically when the page is opened. (It’s easy to use, but don’t use it with large amounts of JS code.) 3. External linkWritten in a separate js file, introduced in the html file using the src attribute of the script tag, it will be automatically executed when the page is opened. (Recommended because there are various optimization methods) Note : It is rarely used in the industry, almost never used. Inline and external links cannot share the same script tag. In principle, the script tag of the external link can be placed anywhere. The script attribute of the external link is src , not href, not href, not href... The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: What is flex and a detailed tutorial on flex layout syntax
>>: Two ways to solve the problem of MySQL master-slave database not being synchronized
1. Unzip the zip package to the installation dire...
I just started learning about databases recently....
1. In addition to the default port 8080, we try t...
Table of contents Introduction Creating an Array ...
When I first started setting up an ftp server on ...
1. Install dependency packages [root@localhost ~]...
The logs in MySQL include: error log, binary log,...
Maybe everyone knows that js execution will block...
background This bug was caused by滾動條占據空間. I check...
Table of contents 1. Resource download 2. Unzip t...
This article example shares the specific implemen...
1. Mycat application scenarios Mycat has been dev...
introduce Have you ever spent a whole day trying ...
Prerequisite: Save the .frm and .ibd files that n...
This article shares the specific code of Vue.js t...