(9)js函数形参与实参的个数可以不同

来源:互联网 发布:outlook smtp 端口号 编辑:程序博客网 时间:2024/06/06 19:45

今年别人写的jsp页面发现,调用者是传入2个参数,而被调用的参数却又三个形参,一下子懵逼了,于是就查询了一番。

1.html是这样的

<a href="javascript:openTab('${sub.menuName }','${sub.menuUrl}')" class="easyui-linkbutton" data-options="plain:true" style="width: 150px;">${sub.menuName }</a>

2.js的函数却是这样的

function openTab(text,url,iconCls){    if($("#tabs").tabs("exists",text)){        $("#tabs").tabs("select",text);    }    else{        var content="<iframe frameborder=0 scrolling='auto' style='width:100%;height:100%' src='${pageContext.request.contextPath}/"+url+"'></iframe>";        $("#tabs").tabs("add",{            title:text,            iconCls:iconCls,            closable:true,            content:content        });    }}

3.参考博客列表
*http://www.cnblogs.com/jphoebe/articles/5141417.html

<html>  <head>    <title>      函数调用测试,参数个数和函数声明不一样多    </title>    <script language="javascript">      function  needtwopara(p1,p2){                var a=arguments;                var result='我是个需要2个参数的函数\n'                                     +'您输入的参数的个数为:'+a.length+'\n'                for(var i=0, len = a.length; i < len; i++){                        result=result+'第'+(i+1)+'个参数为:'+a[i]+'\n'                    }                result+='以上是用arguments来获得参数\n';                result+='下面用变量来获得参数:\n';                result+='p1:'+p1+'\n';                result+='p2:'+p2+'\n';            alert(result);        }     </script>    </head>    <body>       <form>          <input type="button" value="测试1--传递1个参数"            onclick="javascript: needtwopara('smallerpig');">       </form>       <form>          <input type="button" value="测试2--传递2个参数"            onclick="javascript: needtwopara('smallerpig','小小猪');">       </form>       <form>          <input type="button" value="测试3--传递3个参数"            onclick="javascript: needtwopara('smallerpig','小小猪','生命不息');">       </form>       <form>          <input type="button" value="测试4--传递4个参数"            onclick="javascript: needtwopara('smallerpig','小小猪','生命不息','学习不止');">       </form>    </body></html>

*http://www.jb51.net/article/89297.htm