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. <Body>
Onscroll: triggered when the page is rolled. <Body>
Onstop: triggered when the stop button is pressed. <Body>
Onresize: triggered by hour adjustment. <Body>
Onmove: triggered when the window is moved. <Body>
<Body onload = "alert ('page loaded ')" onscroll = "alert ('page rolled')">
Form-related events:
Onblur: triggered when the current element loses focus. <Input>
Onchange: triggered when the current element loses focus and the value changes. <Input>
Onfocus: triggered when the current element obtains the focus. <Input>
Onsubmit: triggered when a form is submitted <form>
<Form method = "" action = "">
<Input type = "" name = ""/>
</Form>
<H1 onclick = "test ()">
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
<Html>
<Head>
</Head>
<Body>
<Input type = "text" name = "name"/>
<H1> suns </Body>
</Html>
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 <input type = "radio" name = "Change document content
1 <Element id = "s"/>
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 ("");
----------------------------------------------
<Table>
<Tbody id = "tb"> document. getElementById ("tb ");
<Tr> <td> suns1 </td> <td id = "td1"> suns2 </td> </tr>
<Tr> <td> suns2 </td> </tr>
</Tbody>
</Table>
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