Javascript learning-2

Source: Internet
Author: User
Javascript Object Data 1 Functionfunctionadd (I, j) {} varfunfunction () {} 2 ObjectJSONvarstudents {name: & quot; suns & quot;, age: 10 getName: function () {}}; 3Array number...

Javascript Object Data
1 Function
Function add (I, j ){

}

Var fun = function (){

}
 
2 Object
JSON
 
Var students = {
Name: "suns ",
Age: 10
GetName: function (){

}
};
 
 
3 Array
Array features:
Var array = ["suns", 10];
Array. length;
Push ();
Pop ();
Shift ();
Unshift ();
Reverse ();
Sort ();
Join ("-d -");
-----------------------------------------
String
Var name = "suns ";
Var name = new String ("suns ");

Java judges that the string content is equal
. Equals ();
Java character Length
. Length ();

 
String API method
ToString (); ---- the string information is displayed when you enter the content on the page.
ValueOf ();


Concat (); --- connect multiple strings
Var name = "sun ";
Sun. concat ("shuai ");

Substring (start position, end position); --- truncates a string
0 does not contain
Split (); ---- split the string into an array according to the specified separator
Var name = "sun, shuai ";
Var array = name. split (",");

IndexOf (); --- determines whether a string is contained
Var name = "sunshuai ";
Name. indexOf ("sh ");

CharAt (); --- get characters at a specific position
Var name = "sunshuai ";
Name. charAt (1); ---> u


FromCharCode (); --- obtains the corresponding character information based on the character code value.
String. fromCharCode (97); ---

Java: String. startWith (); --- boolean
String. endWith (); --- boolean
Determines whether a string starts with a string.

String name = "sunshuai ";
Name. startWith ("suns ");



Note:
Javascript judges strings equal ====
Javascript determines the character length. length attribute
Javascript does not have startWith () endWith ()

Date
Java. util. Date
^
|
Java. SQL. Date

Javascript
Var d = new Date ();

Date API 2011
GetYear (); starts from the year 1900
GetFullYear (); year
GetMonth (); get month ---> 0 start
GetDay (); week
GetTime (); 1970 milliseconds
GetDate (); get the day
ToLocaleString (); time used to display local time


Math
Math. abs (); absolute value
Math. sqrt (); Square
Math. round (); rounding
Math. ceil (); decimal point, round
Math. floor (); decimal point, rounded up
Math. random (); 0-1 random number


---------------------------------------------------
Event model (Observer Design Model)
Event Elements
Event
Event source event ---> event Source
When an event occurs, the event listener discovers and processes the event.


Javascript event model
1. Click the event and double-click the event.
2. Event source tag
3. Event listener attribute processing in the event listener tag

General event listening attributes:
Onclick Click Event
Ondblclick double-click event
Onmouseover
Onmouseout move the mouse out
Onmouseomove Move mouse movement
Onmousedown: press the mouse key
Onmouseup mouse key released
Applies to almost all of the displayed elements.
Page-related event listening attributes:
Onload: triggered when a page is loaded.
Onscroll: triggered when the page is rolled.
Onstop: triggered when the stop button is pressed.
Onresize: triggered by hour adjustment.
Onmove: triggered when the window is moved.


 


Form-related events:
Onblur: triggered when the current element loses focus.
Onchange: triggered when the current element loses focus and the value changes.
Onfocus: triggered when the current element obtains the focus.
Onsubmit: triggered when the form is submitted

 



Instead of calling, it is stored in the event listening attribute,
It is called only when an event occurs.
H1 object
H1.onclick

 


------------------------------------------
Event model (javascript)
1 event
? How to obtain events in javascript programs
FireFox
Function test (event ){

}

IE --- window. event

Get event object
Event. type ---> event type
Event. clientX accuracy of event occurrence X (horizontal coordinates)
Accurate Y of event. clientY event (vertical coordinate)


2. The event source (TAG) uses the event ----> event Source
Firefox
Event.tar get ---> event Source
Ie
Window. event. srcElement

3. event listening Properties
 
-------------------------------------------
Javascript events
Event bubbling bubble
 
1. events generated in the Child tag are transmitted to the parent table tag.
Solve event bubbles
FireFox
Event. stopPropagation ();
IE
Window. event. cancelBubble = true;
----------------------------------------------------
Javascript DOM
Document Object Module

Html document as a tree






Suns



Html
Head body
Input h1
Suns
Javascript DOM
1. Change document content
Change the label attributes of a document
2. Change the document structure
Add new labels for existing documents

A group of Apis

1
Var element = document. getElementById ("s ");
2 "value =" ">
Var elements = document. getElementsByTagName ("h1 ");


1 picture
2 font
This css style
Var div = document. getElementById ("I ");
Div. style. color =;
Div. style. backgroundColor =;

 
-----------------------------------------
The only object of var is document. getElementById ("");
Array of the var tag object = document. getElementsByTagName ("");
 


----------------------------------------------






Document. getElementById ("tb ");
Suns1 Suns2
Suns2

Var td = document. getElementById ("td1 ");


Td. parentNode
Td. nextSibling
Td. previussibling
FirstChild
LastChild
ChildNodes --- child Array

----------------------------------------------
Tree menu www.2cto.com
---------------------------------------------
Change document structure
Var div = document. createElement ("div ");
Element. appendChild (div );

Var body = document. getElementById ("B ");
Body. appendChild (div );

Var txt = document. createTextNode ("suns ");
Div. appendChild (txt );

Parent Child
Body. removeChild (div );

----------------------------------------------
1. Review DOM events
2 menu
3. Dynamic table


Author: woshiyjk
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.