<script language ="javascript">
function [color=red]sayHi()[/color]
{
if([color=red]arguments[/color].length ==1)
{
--此处访问的是sayHi()传过来的第一个参数10,而且function 里面都不用指定参数个数和类型,动态获取。。
alert(arguments[0] + 10);
}
else if(arguments.length ==2)
{
alert(arguments[0] + arguments[1]);
}
[b]--JS语言中的函数和JAVA语言不一样,JS不会去判断传过来的参数个数是否和函数中定义的一样,但是咱们却可以用上面这种方式来达到JAVA语言一样的效果[/b]
}
</script>
<body>
<input type="button" value="test arguments" [color=red]onClick="sayHi(10,20)"/[/color]>
</body>
function [color=red]sayHi()[/color]
{
if([color=red]arguments[/color].length ==1)
{
--此处访问的是sayHi()传过来的第一个参数10,而且function 里面都不用指定参数个数和类型,动态获取。。
alert(arguments[0] + 10);
}
else if(arguments.length ==2)
{
alert(arguments[0] + arguments[1]);
}
[b]--JS语言中的函数和JAVA语言不一样,JS不会去判断传过来的参数个数是否和函数中定义的一样,但是咱们却可以用上面这种方式来达到JAVA语言一样的效果[/b]
}
</script>
<body>
<input type="button" value="test arguments" [color=red]onClick="sayHi(10,20)"/[/color]>
</body>