JavaScript is well worth our learning.
1) All Master browsers support JavaScript.
2) At present, most of the world's Web pages use JavaScript.
3) It can make the Web page to show a variety of dynamic effects.
4) as a web developer, if you want to provide a beautiful web page, to make users satisfied with the Internet experience
, JavaScript is an essential tool.
Basic layout
JavaScript layout must be placed in
The property must be written between <script> and </script> and you can be prompted to set the <script type= "text/javascript></script>
CSS-like selectors,
<script type= "Text/javascript" >
document.write ("Hello");
document.getElementById ("P1"). style.color= "Blue";
</script>
Document selector. Write (input meaning) No other words can appear in the middle of two links
("Hello") parentheses are words that are expressed in the Web page. must be enclosed in quotation marks in parentheses, with a semicolon ending.
document.getElementById ("P1"). style.color= "Blue";
Document selector, the meaning of the user ("P1") Here you need to use the ID selector to connect to the desired content area, note that "consumer" should be aware of the case.
In the style selection with CSS,. style.color= "Blue"; style. Color = "Blue"; ID traps to modify it in JS. Connect with a. Dot number.
JavaScript code can be written not only in the HTML file, we can also separate the HTML file and JS code, and create a separate JavaScript
File (JS), the file suffix is usually JS, and then the JS code directly written in the JS file.
Index.html script.js
In the JS file, you do not need to write <script> tags, directly write JavaScript code on it.
JS file can not be run directly, embedded in the HTML file to execute, we need to add the following code in HTML, you can embed the JS file in the HTML file
<script src= "Script.js" ></script> so you can pull.
JS can be placed anywhere in the HTML file but we usually put it in the head or body of the page.
Put in the
The most common way is to place the <script> element in the head section of the page, and the browser parses the head section to execute the code before parsing the rest of the page.
Put in the <body> section:
The JavaScript code executes when the page reads to the statement.
JavaScript can be placed anywhere in the HTML as a footstep language, but the browser interprets the HTML in chronological order, so the preceding script is executed first. For example, the page display initialization of JS must be placed in the head, because the initialization is required to advance (such as the page body set CSS, etc.), and if the function is executed through the event call the position is not required.
The end of a line is considered the end of the statement, usually preceded by a semicolon ";" to indicate the end of the statement. If you have more than one sentence, execute the statement sequentially.
JS annotations are important.
Annotations can improve the readability of your code, help you and others to read and understand the JavaScript code you write, and the content of the comments will not be displayed on the page. Comments can be divided into single lines and multiline comments.
<script type= "Text/javascript" >
document.write ("single-line comment using '//'"); I am a comment, the parentheses inside the input content of the page.
document.write ("Multi-line comments using/* Comment content */")
/*
Many lines can
So commented out,
Very convenient to use.
*/
</script>
Start learning JavaScript Basics