jquery数据表,按钮呈现但变为禁用

时间:2014-12-02 18:10:57

标签: jquery css datatable

我有一个数据表:

http://s7.postimg.org/po8prohob/enable_Disable.png

当我点击“DISABLE”按钮时,它会变为“ENABLE”和副virsa,但当你点击相同的更改按钮时,它没有像第一次点击那样的任何动作。

// Attach delete
$('#saiMdataEnvListTable .delete').on('click', function() {  
    var ans = confirm("Do you want to delete this Environment?");
    if(ans==true){
        var nRow = $(this).parents('tr')[0];
         var target_row = $(this).closest("tr").get(0); // this line did the trick
            var aPos = oTable.fnGetPosition(target_row); 

              oTable.fnUpdate('T',aPos,1);
              oTable.fnUpdate('<td class="center"><a href="JavaScript:void()" class="button enable" style="margin:10px;margin-right:30px;">Enable</a></td> ',aPos,6);


        $.ajax({
            url: "deleteEnv.do",
            data: "env=" + nRow.id + "&flag=" + "T",
            success: function(response) {
                  oTable.fnDraw(false)
               toastr.success(response.message);  
            }
        })            
    }
}); 

// Attach enable
$('#saiMdataEnvListTable .enable').on('click', function() {  
    var ans = confirm("Do you want to enable this Environment?");
    if(ans==true){
        var nRow = $(this).parents('tr')[0];
          var target_row = $(this).closest("tr").get(0); 
           var aPos = oTable.fnGetPosition(target_row); 
            oTable.fnUpdate('F',aPos,1);
            oTable.fnUpdate('<td class="center"><a href="JavaScript:void()" class="button delete" style="margin:10px;margin-right:30px;">Disable</a></td> ',aPos,6);

        $.ajax({
            url: "enableEnv.do",
            data: "env=" + nRow.id + "&flagt=" + "F",
            success: function(response) {
                 oTable.fnDraw(false)
               toastr.success(response.message);  
            }
        })    
    }
}); 

谢谢,感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

看起来你在启用点击事件中创建了删除按钮元素,因此它可能没有获得它的事件绑定。使用ondelegate将事件处理程序更改为这样,但从文档级别开始

$(document).delegate('#saiMdataEnvListTable .delete', 'click', function (event) {
  // ...
})