如何使用JQuery将HTML表转换为列表?

我将如何转换表格

Name Price
Name Price

到jQuery的段落列表

 
  • Name

    Price

  • Name

    Price

Toggle list view

$("#products-show-list").click(function(){...});

 function convertToList(element) { var list = $("
    "); $(element).find("tr").each(function() { var p = $(this).children().map(function() { return "

    " + $(this).html() + "

    "; }); list.append("
  • " + $.makeArray(p).join("") + "
  • "); }); $(element).replaceWith(list); }

    你可以尝试:

     function convertToList() { var list = $("
      "); $("table tr").each(function() { var children = $(this).children(); list.append("
    • " + children[0].text() + "

      " + children[1] + "

    • "); } $("table").replaceWith(list); }

      这还有一些工作要做,但这是我到目前为止所做的工作:

        
      lakers
      dodgers
      angels
      chargers

      我可以看到这在SharePoint中很有用,它喜欢使用一堆嵌套表来呈现一个使用效率更高的简单列表,