Home  >  Article  >  Web Front-end  >  Jquery table merging problem sharing_jquery

Jquery table merging problem sharing_jquery

WBOY
WBOYOriginal
2016-05-16 18:02:11957browse

Here I use the Jquery library, which I don’t need to introduce too much. There are a few knowledge points:
- Selector tr:eq(index), which means selecting the tr element with the specified index index. The index starts from 0
- tempRow.parent(), which means returning the parent node object of the tempRow object
- $("").prependTo(), which means adding a td element to the content head of the specified element
Example code
index.html

Copy code The code is as follows:



































































































课别 班别 班次 出勤时间
陈伟勋 一班制 白班 2011-09-09
陈伟勋 一班制 夜班 2011-09-09
陈伟勋 两班制 白班 2011-09-09
陈伟勋 两班制 白班 2011-09-09
陈伟勋 两班制 夜班 2011-09-09
陈伟勋 三班制 早班 2011-09-09
陈伟勋 三班制 中班 2011-09-09
陈伟勋 三班制 晚班 2011-09-09
张文军 一班制 白班 2011-09-09
张文军 两班制 白班 2011-09-09
张文军 两班制 白班 2011-09-09
张文军 两班制 夜班 2011-09-09
张文军 三班制 夜班 2011-09-09
张文军 三班制 中班 2011-09-09

<script> <br>var grid = $("#gridview"); <br>var rowCount = grid.find("tr").length - 1; <br>var flagRow = grid.find("tr:eq(" rowCount ")").find("td:eq(0)").html(); <br>var sp = 0; <br>for(var i = rowCount; i >=0; i--) { <br>var tempRow = grid.find("tr:eq(" i ")"); <br>if(flagRow == tempRow.find("td:eq(0)").html()) { <br>tempRow.find("td:eq(0)").remove(); <br>} <br>else { <br>$("<td/>").attr("rowspan", rowCount-i-sp).html(flagRow).prependTo(tempRow.parent().find("tr:eq(" (i 1) ")")); <br>flagRow = tempRow.find("td:eq(0)").html(); <br>sp = rowCount-i; <br>if(i != 0) { <br>tempRow.find("td:eq(0)").remove(); <br>} <br>} <br>} <br></script>



Rendering of commenting out the Jquery code

Rendering of running Jquery code


Summary
The code is very rough, I just made a simple note. I have been busy organizing and writing some Jquery plug-ins and discuz plug-ins recently. The articles related to Python and PyQt have not been compiled and published in the future. Alas, I don’t have enough time, so I can only take my time. Jquery is quite good. With the built-in Sizzle selector, the speed is even faster. It seems that it is now in version 1.6. I hope it gets better and better!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn