Using JavaScript in HTML:
————————————————————————————————————————————————————————
Main content;
First, the use of <script> elements.
Second, embed script and external introduction script.
Third, the impact of document mode on Javasrcipt.
Four, under what circumstances consider disabling JavaScript.
————————————————————————————————————————————————————————
First, the use of <script> elements:
1, the main way to use JavaScript in a Web page is to use the <script> element to achieve. Now the <srcipt> element is a member of the HTML specification, with 6 attributes defined for the <script> element in HTML 4.01:
A, async-optional;
B, CharSet--optional;
C, defer--optional;
D, language--waste;
E, src--optional;
F, type--optional.
—————————————————————————————————————————————————————————
Ii. Embedding scripts and external introduction scripts
There are two ways to use it: the first is to write directly to the HTML page:
<script type= "Text/javascript" >
function Sayhi () {
alert ("Hello");
}
</script>
The code contained within the <script> element will be executed from the top to the next, and the interpreter will interpret a function of a function, and nothing else will change until a function has been interpreted.
The second method: embed the external JS file:
<script type= "Text/javascript" src= "Example.js" ></script>
This will enable the successful introduction of a JS file.
Note that if the JS code is written in the <script></script> element that contains the SRC attribute, the code here is ignored, or the JS file introduced by SRC is executed.
The <script> element is in that position in the HTML tag structure?
The <script> element is between
A few points of doubt:
Everyone knows that the HTML tag is executed from the top to the next line of execution, then the JavaScript tag side in the
The code loads a lot of time very long that would not be, load the time the browser will be blank, the inevitable user experience is poor this is a problem??
There are generally three ways to solve this problem:
1, put the <script> elements on the </body> elements above.
2. Use Lazy Load Properties "defer" Eg:<script type= "Text/javascript" defer= "defer" src= "Example.js" ></script>
3. Asynchronous loading defines the "async" attribute in HTML5.
The <noscript></noscript> tag element prompts the user to turn on the display script in a browser that does not support scripting or a script-disabled browser, and will never appear in a script-enabled browser.
Javasrcipt using JavaScript in---HTML