<script language="javascript">
function Foo(idx)
{
window.alert("121");
}
function fff(){
var obj=document.getElementById("btn");
obj.attachEvent("onclick", Foo);
}

</script><table>
<tr>
<td><input type="button" name="btn" value="改变" onclick="fff()" id="bbb"></td>
</tr>
<tr>
<td><input type="button" name="btn" value="显示"  id="btn"></td>
</tr>
<tr>
<td><input type="button" name="bsrcxbtn" value="查询" onclick="Foo('11')"></td>
</tr>
</table>如何通过点击"改变"按钮,给“显示”按钮添加onclick事件?使得点击“显示”按钮也能弹出对话框?

解决方案 »

  1.   

    <table> 
    <tr> 
    <td> <input   type="button"   name="btn1"   value="改变"   onclick="fff()"   id="bbb"> </td> 
    </tr> 
    <tr> 
    <td> <input   type="button"   name="btn2"   value="显示"     id="btn2"> </td> 
    </tr> 
    <tr> 
    <td> <input   type="button"   name="bsrcxbtn"   value="查询"   onclick="Foo('11')"> </td> 
    </tr> 
    </table> 
    <script>
    function   fff(){ 
    var   obj=document.getElementById("btn2"); 
    obj.setAttribute("onclick","show()");
    }
    function show(){
    alert('ss');
    }
    </script>
      

  2.   

    可以这么去做  document.getElementById("bun2").onclick = function()
    {
       alert("我被点击了");
    };顺便推荐一个web操作系统,做的比较不错。就是Spring+Hibernate+Webwork+ajax开发的。http://www.epopos.cn