<a href="###" onclick="javascript:foo()" id="aa">aaa </a>
<br>
<input onclick="change()" value="change" type=button>
<script language="javascript">
<!--
function foo(){
alert("foo()")
}
function change(){
alert("change()")
document.getElementById("aa").onclick=function(){foo_2()}
}
function foo_2(){
alert("foo_2()")
}//-->
</script>

解决方案 »

  1.   

    <html>
    <head>
    <title>test</title>
    <script language="javascript">
    function foo(){
    alert("执行foo方法");
    }

    function change(){
    document.getElementById("aa").href="javascript:others()";
    }

    function others(){
    alert("执行ohters方法")
    }
    </script>
    </head>
    <body>
    <a href="javascript:foo()" id="aa">aaa</a>
    <br><br>
    <input type="button" value="执行改变的方法" onclick="change()">
    </body>
    </html>
      

  2.   


     最好不要在 href 上加上路径,那样的会容易出现漏洞,会被攻击,因为可以看到你的链接地址,推荐还是使用 onclick 实现吧。
    <html>
    <head>
        <title>test</title>
        <script language="javascript">
            function foo(){
                alert("执行foo方法");
            }
            
            function change(){
                document.getElementById("aa").onclick=function(){others()} 
                alert("事件更换完毕");
            }
            
            function others(){
                alert("执行ohters方法")
            }
        </script>
    </head>
    <body>
    <a href="javascript:void(0)" onclick="foo()" id="aa">aaa</a>
    <br><br>
    <input type="button" value="执行改变的方法" onclick="change()">
    </body>
    </html>
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <script>
      function foo(){alert(1);}
      function foo1(){alert(2);}
      function change(){
    document.getElementById('test').onclick = foo1;
      }  </script>
     </HEAD> <BODY>
      <a id=test href='#' onclick='foo()'>aaaaa</a>
      <input type=button value=change onclick='change()'/>
     </BODY>
    </HTML>