1. Function parameters
variable parameter (indeterminate parameter): variable number of arguments parameters, example of parameter array 1. Sum of all parameters
<! DOCTYPE html>functionsum () {//alert (arguments.length); //alert (arguments[0]); //arguments varResult=0; for(vari=0;i<arguments.length;i++) {result+=Arguments[i]; } returnresult;} Alert (SUM (12, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6, 8, 6));</script>View CodeExample 2:css function to judge arguments.length parameter name, enhance readability<! DOCTYPE html>functioncss (obj, name, value) {if(arguments.length==2)//Get { returnObj.style[name]; } Else //Set{Obj.style[name]=value; }}window.onload=function (){ varOdiv=document.getelementbyid (' Div1 '); Alert (CSS (Odiv,' Width ')); //css (odiv, ' background ', ' green ');};</script>View Code2. Take non-inline styles:
Take a non-inline style (cannot be used to set):
OBJ.CURRENTSTYLE[ATTR]//iegetcomputedstyle (obj, false) [attr]//chrome/ff<! DOCTYPE html>#div1 {width:200px; height:200px; background:red;}</style><script>functionGetStyle (obj, name) {if(Obj.currentstyle)//IE { returnObj.currentstyle[name]; } Else //Chrome/ff { returngetComputedStyle (obj,false) [name]; }}window.onload=function (){ varOdiv=document.getelementbyid (' Div1 '); Alert (GetStyle (Odiv,' BackgroundColor '));};</script>View CodeBut pay attention to the above getstyle () problems, this can only take a single style, if you want to take a compound style, such as the above background, to use the ' backgroundcolor '
3. Array Basics
1) adding, deleting elements
Add to
- Push (Element), added from tail
- Unshift (Element), added from the head
Delete
- Pop (), pops up from the tail
- Shift (), pops up from the head
2) Insert, delete
Splicesplice (start, length, element ...) First Delete, then insert
Splice (start, length)
Splice (start, 0, element ...)
<script>var arr=[1,2,3,4,5,6]; // Delete: Splice (start, length) // Arr.splice (2, 3); // Insert: Splice (beginning, length, element ...); // Arr.splice (2, 0, ' A ', ' B ', ' C '); Arr.splice (2, 2, ' A ', ' B '); alert (arr); </script>
View Code
3) Sort, convert
Sort
- Sort ([comparison function]), sorting an array
Sort a string array sort a numeric array transformation class
Connect two arrays
Use delimiters, combine array elements, generate string string split
<script>var arr=[' float ', ' width ', ' alpha ', ' zoom ', ' left '];arr.sort (arr) ; </script>
View Code
<script>var , 8, arr=[12,];arr.sort ( N1, n2) { return n1-n2; /* if (n1<n2) { return-1; } else if (n1>n2) { return 1; } else { return 0; } */ }); alert (arr); </script>
View Code
4.
----------
Learn Blus teacher JS (2)--Deep JavaScript