将表列分隔为不同的表

时间:2017-06-06 08:36:15

标签: jquery html

我有一项任务是将每列的n列表分隔到不同的表。

我的想法是:

  1. 我在每列中都有@PostMapping("/purchaseToner/{tid}/{bid}") public String buyToner(Model model, @PathVariable("tid") String tid, @PathVariable("bid") String bid){ long bidlong = Long.parseLong(bid) long tidlong = Long.parseLong(tid) //Grab info Buyer mBuyer = buyerService.findOne(bid); Toner mToner = tonerService.findOneToner(tid); ... }
  2. 因此th可能是新列的检测器。
  3. 我需要在每列中找到th
  4. 我需要在tr td
  5. 中使用th-N value创建新的表格N.
  6. 我需要在th
  7. 之后粘贴每个tr td-N

    所以根据我的想法,我写了以下代码:

    th
    jQuery(document).ready(function($) {
        function tableshoot() {
    
            $("table th").each(function() {
                var $this = $(this);
                var thistext = $this.html();
                var index = $this.index();
    
                var tdList = $this.closest("table").find("tr").find("td:eq(" + index + ")").html();
    
                $this.closest("table").append('<table class="mob-table-' + index + '"><tbody><tr><th>' + thistext + '</th></tr></tbody></table>');
    
                $this.closest("table").find("tr").find("td:eq(" + index + ")").each(function() {
                    var tdcontent = $(this).html();
                    $('table.mob-table-' + index + ' tbody').append('<tr><td>' + tdcontent + '</td></tr>');
                });
            });
    
        };
        tableshoot();
    });

    我的问题是:

    这是对的吗?或者有更干净的方法吗?

    无论我的代码是否可行。希望这有助于某人。

1 个答案:

答案 0 :(得分:0)

几件小事:

  1. “find(”tr“)。find(”td:eq(...“更改为”find(tr td:eq ...“
  2. “$(”table th“)。each(function()”change to“$(”table th“)。each(function(index,value)”,用于清理访问索引和值。
  3. jQuery doc each