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;(younger brother)
var B = a.previoussibling, find the previous sibling element of a, note the inclusion of spaces;(brother)
var B = A.parentnode, find the upper-level parent element of A; ( parent)
var B = a.childnodes, find out the array, find the next level of a sub-element;(child)
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 you add it, you first need to create an element.
A.appendchild (obj); Adds a child element to a.
A.removechild (obj); Delete 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 to eighth position from the third position
Alert (S.SUBSTR (3,8)), starting from the third position intercept, intercept eight characters length, do not write the following number is truncated to the last.
S.split ("); Replace the character with the specified character, put in an array, automatically sort
S.length is a property
S.indexof ("World"), where the first occurrence of world in a string is not returned-1
S.lastindexof ("O"); o the last occurrence in the string
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.
Nine, the operation of mathematical functions
Math.ceil (); the smallest integer greater than the current decimal
Math.floor (); The largest integer of the current decimal number of a small fish
MATH.SQRT (); open square
Math.Round (); rounding
Math.random (); random number, 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.
Related element operations