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

今年别人写的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值