function return value
function sum (A, B)
{
Return a+b
}
Can have return, no return, if no return returned undefined
return; also undefinded
A function should return only one type of value
Variable parameter
Arguments array--all parameters
Function Show ()
{
alert (arguments.length);
Gets the array of the arrays
var sum = 0;
for (Var i=0;i<arguments.lenght;i++)
{
Sum +=arguments[i]
}
}
Show (+)
For any number of and
CSS functions
function css ()
{
if (arguments.length = = 2)
{
return arguments[0].style.arguments[1];
}else if (arguments.length = = 3)
{
ARGUMENTS[0].STYLE.ARGUMENTS[1] = arguments[2]
}
Style can only get styles between lines how to get a non-inline style
Currentstyel gets the calculated style can only be used under the ID
Firefox with getComputedStyle (Odiv,false) The second parameter is not used
}
Package GetStyle (OBJ,STTR)
{
if (Obj.currentstyle)
{
return obj.currentstyle[attr]
}else{
Return getComputedStyle (Obj,false) [attr]
}
}
Get background is a composite style, which is undefined
Array
define var arr = [+/-]
var arr = new Array ()
Properties of the array
Length
Can be set or get can be used to empty the array
Arr.length = 0
Push to add an element to the array
Push (3)
Pop
Shift to remove elements from the head of an array
Unshift adding elements to the head of an array
Sorting of arrays
Sort () sorts an array
var arr = [' Z ', ' A ', ' C ', ' B '];
Sort (arr)
var arr = [3,2,4,1]
Sort number out problem
Need to give a comparison function sort (function (n1,n2) {return n1-n2})
Concat () Connect two arrays
ARR3 = Arr1.concat (ARR2)
Join () splits an array
Arr.join (', ')
String Conversions to arrays
var str = ' All-in-all ';
var arr = str.split (', ')
Splice (start, length, Element)
Remove some elements from the middle of an array
Insert some elements
Arr.splice (4,0, ' A ', ' B ') Delete 0, insert some elements
Replace
Arr.splice (, ' A ', ' B ')
Delete the element first, then insert the element
JS Learning 2