Home > Web Front-end > JS Tutorial > What are the ways to introduce javascript into the page?

What are the ways to introduce javascript into the page?

零下一度
Release: 2017-06-24 14:33:04
Original
2378 people have browsed it

This series of js summary involves almost all the knowledge points of js from the basics to the difficult points. If there are any inaccuracies, please correct me. Thank you

1. Inline introduction (not recommended, security performance is very low)

<div onclick=&#39;alert(11)&#39;></div>
Copy after login

2. Embedded (will The js code is written between script script blocks)

<script type=&#39;text/javascript&#39;>alert(11)</script>
Copy after login

3. External link (write the js code in an external file and find the import through src)

<script src=&#39;js/index.js&#39; type=&#39;text/javascript&#39;></script>
Copy after login

Details:

1. In the outer link, in the middle of the script block You cannot write js code, and even if you write it, it will not be executed.

2. We usually put js at the end of the body. The reason is that html pages are loaded sequentially from top to bottom. js usually obtains html notes to give dynamic operation effects. So we need to load the html tag first before loading our js

 

The above is the detailed content of What are the ways to introduce javascript into the page?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template