Home > Web Front-end > JS Tutorial > There are several ways to add javascript to a web page

There are several ways to add javascript to a web page

醉折花枝作酒筹
Release: 2023-01-07 11:43:43
Original
8130 people have browsed it

There are two ways to add js to a web page, namely: 1. Direct method, the syntax format is "<script>js code</script>"; 2. Reference method, the syntax format is "< script src="js address" type="text/javascript">".

There are several ways to add javascript to a web page

1. Direct method

This is the most commonly used method. Most web pages containing Javascript use this method, such as:

<script type="application/javascript">
  <!--
  document.write("这是Javascript!采用直接插入的方法!");
  //-Javascript结束-->
  </script>
Copy after login

In this example, we can see a new tag: <script>...</script>, and .

You can also specify the javascript version when importing the file, for example:

Note: Any content in the script tag that specifies the src attribute will be ignored.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of There are several ways to add javascript to a web 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