function return valueWhat is the execution result of a function return value function can not return a function should return only one type of value
function Pass parameter1
. Variable parameter (indeterminate parameter): ArgumentsVariable number of arguments, parameter array example 1: Sum of all parameters
2. Take non-inline style (cannot be used to set):
obj.currentstyle[attr] getComputedStyle (obj, false) [attr]Example 1:<script>
function sum () (
{
var result=0;
for (Var i=0;i<arguments.length;i++)
{
Result+=arguments[i];
}
return result;
}
Alert (SUM (12, 6, 8, 8, 6, 8, 6, 8));
</script> example 2:css function to judge Arguments.length to give the parameter name, enhance the readability <script>
function css ()
{
if (arguments.length==2)//Get
{
return arguments[0].style[arguments[1]];
}
Else
{
ARGUMENTS[0].STYLE[ARGUMENTS[1]]=ARGUMENTS[2];
}
}
Window.onload=function ()
{
var Odiv=document.getelementbyid (' Div1 ');
Alert (CSS (odiv, ' width '));
CSS (odiv, ' background ', ' green ');
};
</script>
<div id= "Div1" style= "width:200px; height:200px; background:red; " ></div>
Abbreviated version:<script>
function css (obj, name, value)
{
if (arguments.length==2)//Get
{
return Obj.style[name];
}
Else
{
Obj.style[name]=value;
}
}
Window.onload=function ()
{
var Odiv=document.getelementbyid (' Div1 ');
Alert (CSS (odiv, ' width '));
CSS (odiv, ' background ', ' green ');
};
</script>
2. Take non-inline style (cannot be used to set):
obj.currentstyle[attr] getComputedStyle (obj, false) [attr]<style>
#div1 {width:200px; height:200px; background:red;}
</style>
<script>
function GetStyle (obj, name)
{
if (Obj.currentstyle)
{
Return obj.currentstyle[name];//compatible IE version
}
Else
{
return getComputedStyle (obj, false) [name];//compatible FF and Google version
}
}
Window.onload=function ()
{
var Odiv=document.getelementbyid (' Div1 ');
Alert (GetStyle (odiv, ' backgroundcolor '));
};
</script>
<div id= "Div1" >
</div>
js-variable parameter (arguments) take non-inline style