塌陷和uncollaps没有在我的脚本工作

问题描述:

我用法师嵌套网格视图在我的项目,它可以列出基于其包中的所有地块,但折叠/ UnCollapses没有在我的脚本工作塌陷和uncollaps没有在我的脚本工作

错误的是.live不是函数这在我的Jquery版本中不被支持,我已经将它改成了.On,但它仍然不工作,请检查我的脚本并帮助我解决错误。

脚本

<script> 
    $(document).ready(function() { 
     var size = $("#main #gridT > thead > tr >th").size(); // get total column 
     $("#main #gridT > thead > tr >th").last().remove(); // remove last column 
     $("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column 
     $("#main #gridT > tbody > tr").each(function (i, el) { 
      $(this).prepend(
        $("<td></td>") 
        .addClass("expand") 
        .addClass("hoverEff") 
        .attr('title',"click for show/hide") 
       ); 

      //Now get sub table from last column and add this to the next new added row 
      var table = $("table", this).parent().html(); 
      //add new row with this subtable 
      $(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>"); 
      $("table", this).parent().remove(); 
      // ADD CLICK EVENT FOR MAKE COLLAPSIBLE 
      **$(".hoverEff", this).live("click", function() {** 
       $(this).parent().closest("tr").next().slideToggle(100); 
       $(this).toggleClass("expand collapse"); 
      }); 
     }); 

     //by default make all subgrid in collapse mode 
     $("#main #gridT > tbody > tr td.expand").each(function (i, el) { 
      $(this).toggleClass("expand collapse"); 
      $(this).parent().closest("tr").next().slideToggle(100); 
     }); 

    }); 
</script> 

结果是 enter image description here

.live被弃用,在jquery的版本1.9和进一步除去。请使用.on代替:

$("#gridT").on("click",'.hoverEff',function(){ 
     $(this).toggleClass("expand collapse"); 
     $(this).parent().closest("tr").next().slideToggle(100); 
}); 
+0

我相应地对其进行了更改,但现在问题在于其未合拢且仍处于单击事件状态时无法再次合拢它。 – ZKF3340320

+0

请在这里添加工作片段。 –

+0

我刚刚在上面的工作片段中更改了您的代码。你是否需要添加所有工作片段,包括控制器,模型和视图? – ZKF3340320