This article mainly introduces how to use JavaScript in HTML. Interested friends can refer to it. I hope it will be helpful to everyone. tag</strong></span></p> <p> In HTML5, script mainly has the following attributes: async, defer, charset, src, type, </p> <ul class=" list-paddingleft-2"><li><p>async (optional): </p></li></ul> <p> Keywords: asynchronous script, external file, immediate download; </p> <p> When label When this attribute is included, the script (external file) will be downloaded immediately. It is only valid for external script files. You can perform other operations on the page while downloading. After the download is completed, parsing and execution will stop. After execution, parsing will continue, but the execution order cannot be guaranteed. . </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false;"><script src="js/index2.js" async="async"> Copy after logindefer (optional): Keywords: delayed script, external file, delayed loading; When When this attribute is included in the tag, the script can wait until the page is completely parsed or displayed to be executed. It is only valid for external files. If there are two scripts with defer at the same time, due to delay, the execution of the former will be limited to the latter. . Copy after logincharset (optional): Keywords: character set Most browsers have ignored it It's worth it, so few people use it. src (optional): Keywords: external reference Represents the address of the external file that needs to be referenced. type (optional): Keywords: MIME (scripting language content type) To ensure maximum Compatible with limited browsers, the type attribute value is mainly text/javascript. If this attribute is not written, its default value is still text/javascript. Note: When referencing external files, do not add other JS code to the tag. When parsing, the browser will only download the external script file referenced by src, and the code embedded in the table will be ignored. . ## Location of tags<strong></strong></span></p> Usually, we place tags with external files (including CSS files , JavaScript files) are placed in the same location, usually inside the <head> tag. <p></p> But once multiple JavaScript external files are encountered during the parsing process, the page cannot be fully displayed until all external files are loaded, so usually we will put it in the <body> tag at the bottom, as shown below: <p></p> <p style="text-align: center"><img src="https://img.php.cn/upload/article/000/192/893/ac6f5bea3de83af42bfe96a35c51e1c3-0.png" alt=""></p> As mentioned above, there is a defer attribute in <script>, but since it is mentioned in HTML5, HTML5 will ignore it The defer attribute set by the embedded script is currently only supported by IE4~IE7. IE8 will fully follow the HTML5 standard from now on, so placing <script> at the bottom of the <body> tag is still the best choice. <p></p> <p><span style="color: #ff0000"> Advantages of referencing external files<strong></strong></span></p> <ul class=" list-paddingleft-2"> <li>#Easy to maintenance: Putting all JavaScript files together not only It does not touch HTML code, and is more conducive to developers writing and maintaining code. <p></p> </li> <li>Accelerate browsing: If multiple HTML pages reference the same JavaScript external file, this file will only be loaded once (cached), which means that the page loading speed can be accelerated. <p></p> </li> <li>Safety: When referencing external files, if the user views the HTML code, they will not see the JavaScript code, which is more secure than writing it in a tag. <p></p> </li> </ul> <p><span style="color: #ff0000"><noscript>tag<strong></strong></span></p> Literal meaning, NO-script, no script, that is, the browser does not The content in the <noscript> tag will only be displayed when JavaScript is supported. <p></p> <ul class=" list-paddingleft-2"> <li> The browser does not support scripts; <p></p> </li> <li> The browser supports scripts , but JavaScript is disabled; <p></p> </li> </ul> If any of the above two conditions is met, the content within the <noscript> tag will be displayed. <p></p> <p style="text-align: center"><img src="https://img.php.cn/upload/article/000/192/893/ac6f5bea3de83af42bfe96a35c51e1c3-1.png" alt=""></p> The page in the picture above gives the user a message. It will only be displayed when the browser does not support or disables JavaScript. Otherwise, the user will never see it and will not see it. Will affect the display of other elements on the page. <p></p>Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study. <p></p>Related recommendations: <p></p> <p>How to introduce CSS into HTML<a href="//m.sbmmt.com/p-tutorial-396350.html" target="_blank"></a></p> <p>HTML5 storag storage details<a href="//m.sbmmt.com/p-tutorial-396347.html" target="_blank"></a></p> <p><a href="//m.sbmmt.com/p-tutorial-396339.html" target="_blank">HTML5 query page production example</a></p>