In HTML5, you can embed JavaScript code directly in the page and include external JavaScript files. The syntax for embedded scripts is "<script></script>", and the syntax for external scripts It is "".
In HTML5, js code can be used in two ways (embedded script and external script) through the <script> tag. The following article will introduce it to you, I hope it will be helpful to you. </p> <p><span style="font-size: 18px;"><strong>Two ways to use js in html5: </strong></span><br></p>##There are two ways to use the <script> tag: directly Embed JavaScript code in the page and include external JavaScript files; the browser will parse the <script> elements in the order they appear on the page. <p></p> <p>Embedded script: <strong></strong><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><script> //js代码 </script></pre><div class="contentsignin">Copy after login</div></div></p><p>External script:<strong></strong><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><script src="外部js脚本文件"></script></pre><div class="contentsignin">Copy after login</div></div></p><p>Advantages of external script: <strong></strong></p>● Maintainability<p></p>● Cacheable: The browser can cache all external JavaScript files linked to based on specific settings<p></p>● Adaptable to the future<p></p><p><span style="font-size: 18px;"><script> tag<strong></strong></span><br/></p>The main way to insert JavaScript into an HTML page is to use the <script> element. The <p></p><p><script> element has two commonly used attributes: <strong></strong><br/></p>● src: Indicates the external file containing the code to be executed. The src attribute is required if you want to include external JavaScript files through the <script> element. The value of this attribute is a link to an external JavaScript file. <p></p><p>Note: <strong>The <script> element with the src attribute should not contain additional JavaScript code between its <script> and <script> tags. If embedded code is included, only the external script file will be downloaded and executed, and the embedded code will be ignored. JavaScript files from external domains can also be included via the src attribute of the <script> element. </strong></p>Example: <p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><script src="example.js"></script> <script src="//m.sbmmt.com/js/example.js"></script></pre><div class="contentsignin">Copy after login</div></div></p>● Type: Specifies the MIME type of the script. The type attribute indicates the content between the <script> and </script> tags.
Description: MIME type includes two parts: media type and subtype. For JavaScript, the MIME type is "text/javascript".
Note: In HTML5, the type attribute is no longer required. The default value is "text/javascript". JavaScript is the default scripting language in HTML5 and all modern browsers.
Recommended video tutorials: "