Five, related elements operation:
var a = document.getElementById ("id"); Find A;
var B = a.nextsibling, find the next sibling element of a, note the inclusion of spaces;
var B = a.previoussibling, find the previous sibling element of a, note the inclusion of spaces;
var B = A.parentnode, find the upper-level parent element of A;
var B = a.childnodes, find the array, find the next level of a sub-element;
var B = a.firstchild, first child element, LastChild last, Childnodes[n] find a few;
Alert (Nodes[i] instanceof Text); Judging is not the text, is returning true, not returning flase, using if to determine if its value is false, you can remove the space.
Vi. creation, addition and deletion of elements:
var a = document.getElementById ("id"); Find A;
var obj = document.createelement ("tag name"); Create an element
obj.innerhtml = "Hello World"; When adding, you first need to create an element.
A.appendchild (obj); Adds a child element to a.
A.removechild (obj); Deletes a child element.
List of A.selectedindex: Selected is the first;
A.options[a.selectindex] Press the subscript to remove the first option object
Seven, the operation of the string:
var s = new String (); or var s = "AAAA";
var s = "Hello World";
Alert (S.tolowercase ()); Turn lowercase touppercase () to uppercase
Alert (s.substring (3,8)); Intercept from the third position to the eighth position
Alert (S.SUBSTR (3,8)); From the third position to intercept, intercept eight characters length, do not write the following number is truncated to the last.
S.split ("); Replace character with the specified character, put in an array, and sort automatically
S.length is a property
S.indexof ("World"); World the first occurrence in the string, no return-1
S.lastindexof ("O"); o where the last occurrence of the string is
Viii. operation of date and time
var d = new Date (); Current time
D.setfullyear (2015,11,6); /* minus 1 settings on the month you want to set */
D.getfullyear: Take the year;
D.getmonth (): Take the month, take out the less 1;
D.getdate (): Take the day;
D.getday (): Pick up the day of the week
D.gethours (): Take the hour;
D.getminutes (): Take minutes; D.getseconds (): Take seconds
D.setfullyear (): Set the year, note-1 when setting the month.
Eight, the operation of mathematical functions
Math.ceil (); The smallest integer greater than the current decimal
Math.floor (); The largest integer less than the current decimal
Math.sqrt (); Open Square
Math.Round (); Rounded
Math.random (); Random number, between 0-1
Ten, small knowledge points
Outside double quotes, inside the double quotation marks to single quotation marks;
When the row height setting is set in the Div, the row occupied by default is in the middle position (middle of the div in the upper and lower section-"default" vertically centered), no matter how high the setting is.
The value of the text box is a string that needs to be converted to a number using parseint ().
S.match (REG); s represents a string, and Reg represents a string that matches both, and returns a null if two strings do not match.
Summarize:
Third, document:
1. Find
var d = document.getElementById ("ID of element");
var d = document.getelementsbyname ("element name")
var d = document.getelementsbytagname ("label name")
2. Operating element content:
(1) Form element: Text (Input:type=text,input:type=password;textarea;input:type=hidden) button (Submit,reset,button image) selection (radio , Checkbox,select,file) d.value=xxxx; var s = d.value;
(2) Non-form element: H1...h6,p,div,ul,ol,li d.innerhtml = xxxx; var s = d.innerhtml;
3. Manipulating element properties:
D.setattribute (name, value) var s = d.getattribute (name) d.removeattribute (name);
4. Operation element Style:
(1) inline style: D.style.backgroundcolor = "#FFFF00"; var s = d.style.backgroundcolor;
(2) Class attribute: D.classname= ""
5. Operation related elements: Father, son, brother, brother
Outreach: Anonymous functions
No call required and no need to name the function
Document Object Supplement