< table >
     < tbody >
         < tr >
             < td > 这行原来就有 </ td >
             < td >< button class = " del " > 删除 </ button ></ td >
         </ tr >
         < tr >
             < td > 这行原来就有 </ td >
             < td >< button class = " del " > 删除 </ button ></ td >
         </ tr >
     </ tbody >
</ table >
用jquery动态的给button加上click事件,并且能够删除行。
哥哥们,怎么做?

解决方案 »

  1.   


    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <table>
    <tbody>
    <tr>
    <td>这行原来就有</td>
    <td><button class="del">删除</button></td>
    </tr>
    <tr>
    <td>这行原来就有</td>
    <td><button class="del">删除</button></td>
    </tr>
    </tbody>
    </table>
    <script>
    $('button.del').live('click', function(){
    $(this).parents('tr').remove();
    })
    </script>
      

  2.   

    jQuery(function ($) {
                //已有删除按钮初始化绑定删除事件
                $(".del").click(function () {
                    $(this).parents("tr").remove();
                });我的没效果啊??高手看下代码有错吗?
      

  3.   

        $('button.del').live('click', function(){
            $(this).parents('tr').remove();
        })
    动态添加的dom,用live来绑定事件
      

  4.   

    jQuery(function ($) {
      //已有删除按钮初始化绑定删除事件
      $(".del").click(function () {
      $(this).parents("tr").remove();
      });有错吗?我看不错来啊!
      

  5.   

    $('button.del').live('click', function(){
      $(this).parents('tr').remove();
      })
    楼主 近视很严重?
      

  6.   

    不是啊我意思是说用.click(function(){})的方式不行吗?
      

  7.   

    用$("xxx").click(function(){})的方式不行吗?
      

  8.   

    关键是 你 button是不是动态生成的是动态生成的 就用 live来绑定
      

  9.   

    不是动态生成的,我试了试$("xxx").click(function(){}),但是没有删除的效果。
      

  10.   

    把你的demo 整理下 发出来。
      

  11.   

    楼主 去下个firebug 吧,看看有什么报错
      

  12.   

    <table>
         <tbody>
             <tr>
                 <td> 这行原来就有 </td >
                 <td><button class = "del"> 删除 </button></td>
             </tr>
             <tr>
                 <td> 这行原来就有 </td>
                 <td><button class = "del" > 删除 </button></td>
             </tr>
         </tbody>
    </table> 
    <script>
    //    $('.del').live('click', function () {
    //        $(this).parents('tr').remove();
    //    }) 
     $('.del').click(function () {$(this).parents('tr').remove();
    </script>这个用你给的代码可以,我注释掉你的代码,用下面的jquery代码就不行了。不明白!