【问题标题】:count how many first columns in each table计算每个表中有多少第一列
【发布时间】:2018-11-10 18:44:15
【问题描述】:

我有 2 个表,第一个表有 2 列,第二个表有 3 列,我使用 ckeditor,所以我不知道如何添加不同的类名。所以在这个表中有类名'table'。我想计算每个表中有多少第一列,如果第一列> 2,则给出包装类,到目前为止我的代码是这样的:

<script type="text/javascript">
  $(document).ready(function(){
      $('.prosiding-content iframe').wrap('<div class="map-responsive"></div>');
      // $('.prosiding-content table').wrap('<div class="table-responsive"> </div>');
      $('.prosiding-content table').addClass('table');

      $('.prosiding-content img').addClass('img-responsive');

var table= $(".prosiding-content table").find("td:first").length;

if (table>2) {
  $(this).wrap('<div class="table-responsive"> </div>');
}

  });
</script>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    您可以只计算任何现有行内的列数(假设表在行内具有相同的列数)并添加所需的类。

    var tables = editor.editable().find( 'table' ).toArray();
    
    CKEDITOR.tools.array.forEach( tables, function( table ) {
      var header = table.findOne( 'tr' );
    
      if ( header && header.getChildCount() > 2 ) {
        table.addClass( 'multiple-columns' );
      }
    } );

    请使用https://codepen.io/jacekbogdanski/pen/xzVYXL codepen 作为工作示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 2011-08-04
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多