<javascript> 
function user_select(toid, toname) {
        var a = "ab";
    }
    function user_select() {
        var a = "dd";
    }
</javascript>
 <input title="添加1" onclick="user_select('a','b')"type="button" value="添 加1" name="button" />
              <input title="添加2" onclick="user_select()"type="button" value="添 加2" name="button" />
为什么我点击添加1 执行不带参数的user_select()函数
而不执行带参数的user_select()函数呢??

解决方案 »

  1.   

    定义JavaScript函数时,函数名是函数对象的标识,参数数量只是这个函数的属性。靠定义参数数量不同的函数实现重载是不行的。
      

  2.   

    可以看看这个http://hi.baidu.com/sjbh_blog/item/b3b0775c3566bd11aaf6d7a1
      

  3.   

    我写个可以实现重载的函数吧function user_select(toid, toname) {
        if (arguments.length == 0) {
            var a = "dd";
        } else if (arguments.length == 2) {
            var a = "ab";
        }
    }