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?

零下一度
零下一度Original
2017-06-24 14:33:042384browse

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>

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

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

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>

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!

Statement:
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