代码之家  ›  专栏  ›  技术社区  ›  GeoffreyF67

网格的第一列是标题?

  •  2
  • GeoffreyF67  · 技术社区  · 17 年前

    是否有一种方法(使用jquery、yui或其他一些JS库)来显示在第一列中包含标题的网格?

    也就是说,我想要:

    Name       Geoffrey
    EMail      GMan67@..
    Username   GJFM
    

    而不是:

    Name      EMail      Username
    Geoffrey  GMan67@..  GJFM
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Nadia Alramli    17 年前

    是的,有一种方法可以做到这一点,我花了一个小时来写作,但这是一个很好的练习:)

    这将就地切换标题和列。这两种方法都有效。也就是说,你可以用它来回切换两种风格。

    // number of columns
    columns = $('table.flipme th').size();
    // number of rows minus one to exclude the header
    rows = $('table.flipme tr').size() - 1;  
    $table = $('table.flipme');
    
    // Add rows to the table to equal the number of columns
    while (rows < columns){
        $table.append('<tr></tr>');
        rows++
    }
    
    // flip in place and mark the old rows and
    // columns as a duplicate to be removed
    for (i=1; i<=rows; i++){
        $('tr')
        .children(':nth-child(' + i + ')').addClass('delete')
        .clone(true).removeClass('delete')
        .appendTo('tr:eq(' + i + ')');
    }
    // remove dublicate
    $('.delete').remove();
    
        2
  •  1
  •   Tracker1    17 年前

    您要创建的是一个透视表。不过,我不知道有什么现成的解决方案。