The number of function parameters in JS is not to determine the difference function, that is to say you define a function a (x, y) when you use this function, you can a (); A (1); (A); A (All-in-one); This is called the A (x, y) function.
Example:
<title>
Function call test, the number of parameters and function declaration is not as many
</title>
<script language= "JavaScript" >
function Needtwopara (P1,P2) {
var a=arguments;
var result= ' I'm a function that needs 2 parameters \ n '
+ ' The number of parameters you have entered is: ' +a.length+ ' \ n '
For (var i=0, len = a.length; i < Len; i++) {
result=result+ ' + (i+1) + ' parameters are: ' +a[i]+ ' \ n '
}
result+= ' above is using arguments to obtain parameters \ n ';
result+= ' Use variables to get parameters: \ n ';
result+= ' p1: ' +p1+ ' \ n ';
result+= ' P2: ' +p2+ ' \ n ';
alert (result);
}
</script>
<body>
<form>
<input type= "button" value= "Test delivery 1 Parameters"
onclick= "Javascript:needtwopara (' Zhouli ');" >
</form>
<form>
<input type= "button" value= "Test 2--pass 2 parameters"
onclick= "Javascript:needtwopara (' Zhouli ', ' Li ');" >
</form>
<form>
<input type= "button" value= "Test 3--pass 3 parameters"
onclick= "Javascript:needtwopara (' Zhouli ', ' Li ', ' Journey '); >
</form>
<form>
<input type= "button" value= "Test 4--pass 4 parameters"
onclick= "Javascript:needtwopara (' Zhouli ', ' Li ', ' Journey ', ' Linkage_aya '); >
</form>
</body>