JavaScript Basics 1

Source: Internet
Author: User
Tags script tag

Re-organized a native javascript:

What is ①.javascript?
JavaScript is a kind of literal translation scripting language, which is a dynamic type, a weak type and a prototype-based language.
In short, JS is a very powerful thing, usually used to control HTML pages, respond to browser operations, verify the transfer of data and so on.
What is the relationship between Java and JavaScript? There is no relationship, at most, the grammatical logic is more like;
What's the relationship between JQuery and JavaScript? Why do you want to learn JS? jquery is a combination of a number of JS code into the more aspects of the plug-in library;

Where to write the ②.javascript code:
The JavaScript code should be inside the script tag of the page, or in a separate JS file, or inside the tag (not recommended);
The script tag can be placed anywhere, but the loading order should be noted in different locations, usually before head end and before body ends
The script tag can be tagged with attributes type= ' text/javascript ' or language= ' JavaScript ' or not written;
Script introduces external JS file path with src <script src= "" ></script>;

③. What to note when writing JS code?
1. Strictly case-sensitive;
2. Statement characters are half-width characters;
3. Write a semicolon after each complete statement;
4. To indent the code, indent to align, and use the Space tab to indent.

Note 1. Add Window.onload=function () {} When the script code is placed before the body and it involves an action tag;

④.js how to find the corresponding tag/node/element

1 document.getElementById (' ID name ') find 2 document.getelementsbyclassname (' Class name ') by ID Find all class names   [with compatibility issues]3 document.getelementsbyclassname (' class name ') [0] Looking for the first class name. The subscript starts at 0.  4 document.getelementsbytagname () Find all </li> <li>document.getelementsbytagname by tag    ( ) [0] Looking for the first one through the label, the subscript is starting from 0

The HTML content inside the ⑤.innerhtml= ' element is displayed. eg

document.getElementsByTagName (' div ') [0].innerhtml = ' Hello world! ';
Display content in the first div tag of the page Hello world! where "=" an equal sign is called assignment, the right side of the content is left. "" "" "called string

6. Click event Xxx.onclick = Event function.

1 function () {2//alert (' Hello world! '); 3 // This is the only object that triggers this event, and here is document.getElementById (' wrap ') 4 this. InnerHTML = ' Hello world! '; 5 };

7. Xxx.onmouseover mouse Move-in events and Xxx.onmouseout mouse-out events

1      //Defining Variables2      varOdiv =document.getelementbyid (' AA '));//id= ' AA '3      varODiv1 =document.getelementsbyclassname (' box ') [0];//class= ' box '4      //Set div initial display5odiv.innerhtml = ' Hello. I'm id= ' AA ';6odiv1.innerhtml = ' Hello. I'm class= ' box ';7 8       //when the mouse moves into the #aa, the. box displays ' Mouse is currently on the #aa Div ';9Odiv.onmouseover =function(){Tenodiv1.innerhtml = ' mouse on the current div in #aa '; One       }; A         //when the mouse moves out of the #aa的时候, the. box clears the content; -Odiv.onmouseout =function(){ -odiv1.innerhtml = ' '; the       }; -};

8. Notes

Multiline Comment:/* Comment */

Single-line Comment://comment

9.JavaScript output:

JavaScript is usually used to control HTML pages, so it is generally said that the output is to modify the content of the page elements;

1   InnerHTML = ' hellow world ',2 document.write (' Hellow world ');

10.JavaScript pop-up window:

1 alert (' Hellow world '); // displays an alert box with a specified message and an OK button.  23 confirm (' OK? ‘); // displays a dialog box with the specified message and OK and Cancel buttons.  45 prompt (' Please enter your name '); // displays a dialog box to prompt the user for input. 

JavaScript Basics 1

Related Article

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.