本帖最后由 wang_yeepay 于 2010-05-04 01:04:53 编辑

解决方案 »

  1.   

    用document.getElementsByTagName把所有的button都找出来在循环添加呗
      

  2.   

    使用jQuery的选择器
    $(":button").click(function(){
      //do something
    })
    如果所有button放在一个form中,且只绑定本form中的button,则
    $("#formid > :button").click(function(){
      //do something
    })
      

  3.   


     <!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>
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
    <title>测试</title>
    <style><!--body,td{font-size: 12px;}--></style>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
    $(".test").click(function(){
      var id = $(this).attr("id");
    var name = $(this).attr("name");
    alert("被点击名字:"+name+"id:"+id)
    });

    });
    </script>
    </head>
    <body>
    <input type="button" class="test" name="button1" id="id1" value="确定">
    <input type="button" class="test" name="button4" id="id4" value="确定">
    <input type="button" class="test" name="button6" id="id6" value="确定">
    <input type="button" class="test" name="button7" id="id7" value="确定">
    </body>
    </html>