<input id="test" type=button value="test" onclick="alert('1');"> 
<input type=button value="更改" onclick="aaa()"> 
<script> 
function aaa() { 
var test = document.getElementById("test"); 
test.onclick = function() {alert('2');} //放到函数里

</script> 

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>无标题页</title>
    </head>
    <body>
    <input id="test" type=button value="test" onclick="alert('1');"> 
    <input type=button value="更改" onclick="aaa()"> 
    <script> 
    function aaa() { 
    var test = document.getElementById("test"); 
    test.onclick = function(){alert("2")} 

    </script> 
    </body>
    </html>要用函数初始化
      

  2.   

    <input id="test" type=button value="test" buttonValue="1" onclick="alert(this.buttonValue);"> 
    <input type=button value="更改" onclick="aaa()"> 
    <script> 
    function aaa() { 
    var test = document.getElementById("test"); 
    test.buttonValue = 2; 

    </script>
      

  3.   

    <input id="test" type=button value="test" onclick="alert('1');">
    <input type=button value="更改" onclick="aaa()">
    <script>
    function aaa() {
    var test = document.getElementById("test");
    test.onclick = alertMe;
    }
    function alertMe()
    {
    alert(2);
    }
    </script>
      

  4.   

    楼上都对<input id="test" type=button value="test" onclick="alert('1');"> 
    <input type=button value="更改" onclick="aaa()"> 
    <script> 
    function aaa() { 
    var test = document.getElementById("test"); 
    test.onclick = new Function("alert('2');"); 

    </script>