1. Related element operation:
var a = document.getElementById ("id");
var B = a.nextsibling, find the next sibling element of a, note the space
var B = a.previoussibling, find the previous sibling element of a, note the space
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 child 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 not flase, you can remove the space.
2. Creation, addition, deletion of elements
var a = document.getElementById ("id");
var obj = document.createelement ("tag name"); Create an element obj.innerhtml = "Hello World";
A.appendchild (obj); add a child element.
A.removechild (obj); Delete a child element.
A.selectindex in the list: Select the first; A.options[a.selectindex] Press the subscript to remove the number of option objects
3: Manipulation of strings
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 character with the specified character
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
4. Small Knowledge Points:
In the Div, the row height setting is the same as the entire outer height to be centered vertically and centered on the row.
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.
5. Form Validation:
(1). Non-null verification (go blank)
(2). Contrast verification (compared to a value)
(3). Scope validation (judging by a range)
(4). Fixed format verification: Phone number, social Security number, email, credit card number
6. Regular Expressions:
Use symbols to describe writing rules:/ Middle Write Regular expression/
^: match at the beginning, $: match end;/^ve/with ve beginning/ve$/with VE end
\d: An arbitrary number
\w: An arbitrary number or letter
\s: arbitrary string
{n}: Repeat n-times the expression on the left
{M,n}: Repeat the expression on the left at least m times, up to N times
{m,}: Repeat at least M-times the expression on the left, at most
+: The expression on the left appears at least once, at most, equal to {1,}
*: The expression on the left appears at least 0 times, at most, equal to {0}
?: the expression on the left appears at least 0 times and appears at most 1 times, equivalent to {0,1}
[A,b,c]: Only one of the contents in square brackets can be taken
[A-z] or [1-9]: Take one of the ranges
|: delegate or; (): priority; \: Escaped--"\ (\)" This is the parenthesis that will appear, need to be escaped
7. Other validation
8. Date-time operation
var d = new Date (); Current time
var d = new Date (1999,3,2); Define a time, April 2, 1999, 3 to add 1
D.getfullyear (): Take the Year; D.getmonth (): Take the month, take out the less 1; d.getdate (): Take the day; D.getday (): Take the Week
D.gethours (): Take hours; D.getminutes (): Take minutes; D.getseconds (): Take seconds
9. 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
10. Event:
Events have three elements: event source, event data, event handler
Event bubbling: When an element is nested, an event is fired by the inner element, and the corresponding event of the external element is then triggered by default.
can add return false;
OnClick: mouse click Trigger
OnDblClick: Double-click Trigger
onMouseOver: Mouse movement above trigger
onMouseOut: Triggers when the mouse leaves
OnMouseMove: Triggers when the mouse moves above
onchange: Whenever content changes trigger
Onblur: triggers when losing focus
Onfocus: Triggers when focus is acquired
OnKeyDown: Trigger when button is pressed
OnKeyUp: Trigger When the button is lifted up
onkeypress: event occurs when the user presses and releases any alphanumeric keys. However, the system buttons (for example: arrow keys, function keys) cannot be identified.
Dom manipulation of JavaScript (iii)