There is only one valid function definition possible but you can script
your function to receive a varying number of arguments. For instance
function functionName (arg0, arg1, arg2, arg3) {
arg0 = arg0 == void 0 ? 0 : arg0;
arg1 = arg1 == void 0 ? 0 arg1;
arg2 = arg2 == void 0 ? 0 arg2;
arg3 = arg3 == void 0 ? 0 arg3;
...
}
checks for each of the four defined formal parameters arg0 .. arg3
whether actually a value has been passed and if not assigns some
default value.If you don't know the number of arguments at all you don't need to
define any formal parameters but you can use the
arguments
array to access the arguments dynamically e.g.
function functionName () {
for (var a = 0; a < arguments.length; a++)
alert(arguments[a]);
}
functionName (1, 2, 3);
functionName ('Net_lover', 'JavaScript', 'http://lucky.myrice.com');
loops through the argument array and alerts every argument passed in.You can also combine the two methods as in
function functionName (arg0, arg1) {
alert('arg0: ' + arg0);
alert('arg1: ' + arg1);
for (var a = 2; a < arguments.length; a++)
alert('additional argument: ' + arguments[a]);
}
functionName ('Net_lover', 'meng', 'Net_lover', 'http://lucky.myrice.com');
your function to receive a varying number of arguments. For instance
function functionName (arg0, arg1, arg2, arg3) {
arg0 = arg0 == void 0 ? 0 : arg0;
arg1 = arg1 == void 0 ? 0 arg1;
arg2 = arg2 == void 0 ? 0 arg2;
arg3 = arg3 == void 0 ? 0 arg3;
...
}
checks for each of the four defined formal parameters arg0 .. arg3
whether actually a value has been passed and if not assigns some
default value.If you don't know the number of arguments at all you don't need to
define any formal parameters but you can use the
arguments
array to access the arguments dynamically e.g.
function functionName () {
for (var a = 0; a < arguments.length; a++)
alert(arguments[a]);
}
functionName (1, 2, 3);
functionName ('Net_lover', 'JavaScript', 'http://lucky.myrice.com');
loops through the argument array and alerts every argument passed in.You can also combine the two methods as in
function functionName (arg0, arg1) {
alert('arg0: ' + arg0);
alert('arg1: ' + arg1);
for (var a = 2; a < arguments.length; a++)
alert('additional argument: ' + arguments[a]);
}
functionName ('Net_lover', 'meng', 'Net_lover', 'http://lucky.myrice.com');
解决方案 »
- 请问有好的滚动层的方法吗,可以适合很多浏览器的,不会被360的屏蔽掉
- 如何将html中JavaScript中某一变量的值传递到下一个js文件中
- JS 语法问题
- 有谁用过Niceforms v.10 ,如何解决控件不能用onblur各其他事件
- 请问window.open()里面的location=yes做哪些事情
- 我用sun.misc.BASE64Encoder进行编码,但在JAVACRIPT中怎么解码啊?从网上找了一些,不能用,特别是处理中文时。HELP ME!
- 急!!!怎样使两个下拉框的选定索引相同?解决马上给分
- 郁闷,散分!!顺便问一下怎样吧string转为Number?
- Can you help me???
- javascript请指点 这个代码看不懂。
- 为什么以下函数无法防止输入汉字,怎样解决?
- 清空地址信息
function functionName(arg0, arg1, arg2, arg3)
{
if (arg0 == void 0)
arg0 = 0
else
arg0 = arg0;if (arg1 == void 0)
arg1 = 0
else
arg1 = arg1;
if (arg2 == void 0)
arg2 = 0
else
arg2 = arg2;if (arg3 == void 0)
arg3 = 0
else
arg3 = arg3;
alert(arg0)
alert(arg1)
alert(arg2)
alert(arg3)
}
</script><input type=button onclick="functionName('a','b')" value=test>