The <script> tag In HTML5, script has the following attributes: async, defer, charset, src, type,
Keywords: asynchronous script, external file, immediate download; When the tag contains this attribute, the script (external file) will be downloaded immediately. It is only valid for external script files. Other operations on the page can be performed while downloading. Parsing and execution will be stopped after downloading is completed, and parsing will continue after execution, but the execution order cannot be guaranteed. <script src="js/index2.js" async="async"></script>
Keywords: Delayed script, external file, delayed 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, the former will be executed before the latter due to the delay. <script src="js/index1.js" defer="defer"></script>
Keywords: character set Most browsers already ignore its value, so it is rarely used.
Keywords: external reference Indicates the address of the external file that needs to be referenced.
Keywords: MIME (content type of scripting language) To ensure maximum browser compatibility, the type attribute value is still 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 in 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. Position of the <script> tag Usually, we put references to tags with external files (including CSS files, JavaScript files) in the same location, usually in the <head> tag. However, once multiple JavaScript external files are encountered during the parsing process, the page cannot be fully displayed until all external files are loaded, so we usually put it at the bottom of the <body> tag, as shown below: It was mentioned above that <script> has the defer attribute, but as mentioned in HTML5, HTML5 will ignore the defer attribute set for embedded scripts. Currently, only IE4~IE7 still support the defer attribute. IE8 and later will fully follow the HTML5 standard, so putting <script> at the bottom of the <body> tag is still the best choice. Advantages of Referencing External Files
The <noscript> tag The literal meaning is NO-script, no script, that is, when the browser does not support JavaScript, the content in the <noscript> tag will be displayed.
If any of the above two conditions are met, the content within the <noscript> tag will be displayed. The page above gives users a message that will only be displayed when the browser does not support or disables JavaScript. Otherwise, the user will never see it and it will not affect the display of other elements on the page. Summarize The above is the example code of using JavaScript in HTML that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! |
<<: Will the most successful companies in the future be technology companies or design companies?
>>: Practice of implementing user login through front-end and back-end interaction of Node.js
Omit the protocol of the resource file It is reco...
Table of contents introduce Example Summarize int...
1. Experimental description In the virtual machin...
Go is an open source programming language that ma...
1. Introduction Some time ago, there were a serie...
Table of contents Overview 1. Function debounce 2...
This article uses an example to describe the erro...
Enable remote access Enable remote access rights ...
This article shares with you the detailed install...
Table of contents Preface start Preface The defau...
1. CSS3 animation ☺CSS3 animations are much easie...
clear:both is used to清除浮動This is the impression I...
Install Remote-SSH and configure it First open yo...
Preface As we all know, HTML5 belongs to the Worl...
This article mainly records the effect of using j...