Using JavaScript in HTML

Source: Internet
Author: User

<script> elementsProperties Async: Optional. The async attribute specifies that once a script is available, it executes asynchronously, indicating that the script should be downloaded immediately, but without interfering with other actions on the page, such as downloading additional resources or waiting for other scripts to load. The Async property applies only to external scripts (only when using the SRC attribute). CharSet: Optional. Represents the character set of the code specified by the SRC attribute. Because most browsers ignore its value, it is seldom used. defer: Optional. Indicates that the script can be deferred until the document is fully parsed and displayed before execution. Valid only for external script files. It is best to include only one deferred script. The implementation of HTML5 ignores the defer property that is set for the embedded script. src: Optional. Represents the external file that contains the code to execute. type: optional. Can be seen as an alternative attribute of language, which represents the content type (also called MIME type) of the scripting language in which the code is written. The MIME type used by the server when transmitting JavaScript files is usually application/x-javascript.
        The JS code contained within the <script> element will be interpreted from top to bottom. The interpreter saves the interpreted function and variable in its own environment, and the rest of the page is not loaded or displayed by the browser until the interpreter evaluates all the code inside the <script> element.

because according to the rules of embedded code, when the browser encounters the string "</script>", it will be considered as the end of the label, and the escape character "/" can solve the problem.

12345 <script>window.onload = function(){alert("<\/script>");}</script>

the server usually needs to look at the extension to determine which MIME type to apply to the response. If you do not use the. js extension, make sure that the server returns the correct MIME type.

    the <script> element with the SRC attribute should not be between its <script> and </script> tagscontains additional JavaScript code. If embedded code is included, only the external script file is downloaded and executed, and the embedded codewill be ignored. usage in XHTML
12345678910111213 <script type="text/javascript">//<![CDATA[function compare(a, b) {if (a < b) {alert("A is less than B");} else if (a > b) {alert("A is greater than B");} else {alert("A is equal to B");}}//]]></script>



From for notes (Wiz)

Using JavaScript in HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.