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">".
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>
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!