This article mainly introduces the use of JavaScript example code in HTML. Friends who need it can refer to the ## tag<strong></strong></span></p> In HTML5, script mainly has the following attributes: async, defer, charset, src, type, <p></p> <ul class=" list-paddingleft-2"> <li>async (optional): <p></p> </li> </ul> Keywords: asynchronous script, external file, immediate download; <p></p> When the tag contains this attribute, the script (external file) will be downloaded immediately. It is only valid for external script files. The page can be downloaded at the same time. For other operations, parsing and execution will stop after the download is completed, and parsing will continue after execution, but the execution order cannot be guaranteed. <p></p> <p class="jb51code"><br><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:xhtml;"><script src="js/index2.js" async="async"> Copy after login#defer (optional): Keywords: delay script, external file, delay Loading; When the tag contains this attribute, the script can wait until the page is completely parsed or displayed before execution. It is only valid for external files. If there are two scripts with defer at the same time, due to delay , the former will be limited to the execution of the latter. Copy after login charset (optional): Keywords: character set Most browsers have ignored its value, 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<span style="color: #ff0000"><strong></strong></span> 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> <p style="text-align: center"><img src="https://img.php.cn/upload/article/000/000/007/cb4279669870b58719990cf972e603ca-0.png" alt=""> 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> <p> Advantages of referencing external files<span style="color: #ff0000"><strong></strong></span></p> <ul class=" list-paddingleft-2">#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. <li><p></p></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. <li><p></p></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. <li><p><br></p></li> </ul>##<noscript>tag<p><span style="color: #ff0000"><strong></strong> Literally, NO-script, no script, that is The content in the <noscript> tag will only be displayed when the browser does not support JavaScript. </span></p> <p></p>The browser does not support scripts;<ul class=" list-paddingleft-2"> <li> <p></p>Browse The server supports scripts, but JavaScript is disabled; </li> <li> <p></p> If any of the above two conditions is met, the content within the <noscript> tag will be displayed. </li> </ul> <p></p> <p style="text-align: center"> The page above gives the user a message, which will only be displayed when the browser does not support or disables JavaScript, otherwise the user will never see it and will not Will affect the display of other elements on the page. <img src="https://img.php.cn/upload/article/000/000/007/e6f2519bbf36ece4d3bf4bdb4874962c-1.png" alt=""></p>