1. Internal JS: In the page directly in the <script></script> tag to write JS code
Advantages: Compared to the use of inline JS, the internal JS code is more centralized, and the page structure of the implementation of the code is less coupling, easier to maintain
Disadvantage: JS code is limited to the use of the current page, the code can not be reused by multiple pages, resulting in a high degree of code redundancy
2. External JS: Introduction of external JS file (recommended)
Advantages: 1. Page code and JS code to achieve effective separation, reduce coupling degree
2. Easy to maintain and extend the code
3. Facilitates the reuse of code
3. Inline JS: Statements nested directly in HTML
This approach is not recommended in development,
(1) Because this way with the page structure code coupling too strong, late maintenance is very inconvenient,
(2) and this way in the development process will result in a lot of redundant code
Three ways to use JavaScript in HTML and pros and cons