我有一个动态表,用户可以在其中添加行或列,我还使用 colResizable 使它灵活,以便用户能够调整列的大小。当我添加此插件时,它不适用于新创建的单元格。
这是我的资料

$(document).ready(function() {
   $( "#container table" ).colResizable({ liveDrag : true });
   //... Other stuffs
}

此功能创建列
function insert_column(element, position)
{
   element.parent().parent().find('tr').each(function() {
      var index = 0;
      $(this).find('td').each(function() {
         if (index == position)
         {
             $(this).after('<td>&nbsp;</td>');
         }
         index++;
      });
   });
   $( "#container table" ).colResizable({ liveDrag : true });
}

如果您愿意,可能是因为某些CSS,这是我在#container和表中拥有的唯一CSS
#container {
    float: left;
    width:800px;
    height:100%;
    overflow:hidden;
    padding: 7px;
    border: 2px #BBB dashed;
}
#container table {
    width: 100%;
    table-layout: fixed;
    background-color:#FCFCFC;
}
#container td {
    border-spacing: 2px;
    min-height: 17px;
    min-width: 50px;
    border: 1px #CCC dotted;
}

怪异的部分是,如果我注释或删除colResizable,它可以用于添加列,但是如果启用,它会添加列但不可见并且无法调整大小。
任何帮助将不胜感激。

最佳答案

引用:
https://github.com/alvaro-prieto/colResizable/issues/2#issuecomment-5198584

//Disable the plugin first
$( "#container table" ).colResizable({ disable : true });

insert_column();

//Re-init the plugin on the new elements
$( "#container table" ).colResizable({ liveDrag : true });

09-25 18:48