Javascript: passing arguments to a function |
|
|
|
Written by Administrator
|
sabato, 23 agosto 2008 |
Javascript functions have a special property containing
an array of the parameters passed.
This property called arguments can be handled to adapt
the function, that can then changes depending on the arguments.
The example here below prints in alert all the parameters:
<SCRIPT Language="JavaScript">
function function1() {
var argv = function1.arguments;
var argc = argv.length;
for (var i = 0; i < argc; i++) {
alert("Argument" + i + " = " + argv[i]);
}
}
</SCRIPT>
You can call the function with the below code:
<SCRIPT Language="JavaScript">
function1('parametro1','parametro2');
</SCRIPT>
|
Last Updated ( sabato, 23 agosto 2008 )
|