Home >Web Front-end >JS Tutorial >Code examples of using JavaScript in HTML
This article mainly introduces the use of JavaScript example code in HTML. Friends who need it can refer to the
##3f1c4e4b6b16bbbd69b2ee476dc4f83a tag
In HTML5, script mainly has the following attributes: async, defer, charset, src, type,<script src="js/index2.js" async="async"></script>
<script src="js/index1.js" defer="defer"></script>
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. .
## 3f1c4e4b6b16bbbd69b2ee476dc4f83aLocation of tags Usually, we place tags with external files (including CSS files , JavaScript files) are placed in the same location, usually inside the 93f0f5c25f18dab9d176bd4f6de5d30e tag.
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 6c04bd5ca3fcae76e30b72ad730ca86d tag at the bottom, as shown below:
As mentioned above, there is a defer attribute in 3f1c4e4b6b16bbbd69b2ee476dc4f83a, 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 3f1c4e4b6b16bbbd69b2ee476dc4f83a at the bottom of the 6c04bd5ca3fcae76e30b72ad730ca86d tag is still the best choice.
Advantages of referencing external files
Literally, NO-script, no script, that is The content in the 2b0b25ff593c5b6c03403dd6234ffb2c tag will only be displayed when the browser does not support JavaScript.
The browser does not support scripts;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.
The above is the detailed content of Code examples of using JavaScript in HTML. For more information, please follow other related articles on the PHP Chinese website!