01 | ////合併上下欄位(colIdx) |
02 | jQuery.fn.rowspan = function(colIdx) { |
03 | return this.each(function() { |
04 | var that; |
05 | $('tr', this).each(function(row) { |
06 | var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this); |
07 | if ((that != null) && ($(thisRow).html() == $(that).html())) { |
08 | rowspan = $(that).attr("rowSpan"); |
09 | if (rowspan == undefined) { |
10 | $(that).attr("rowSpan", 1); |
11 | rowspan = $(that).attr("rowSpan"); |
12 | } |
13 | rowspan = Number(rowspan) + 1; |
14 | $(that).attr("rowSpan", rowspan); |
15 | $(thisRow).remove(); ////$(thisRow).hide(); |
16 | } else { |
17 | that = thisRow; |
18 | } |
19 | that = (that == null) ? thisRow : that; |
20 | }); |
21 | alert('1'); |
22 | }); |
23 | } |
24 |
25 | ////當指定欄位(colDepend)值相同時,才合併欄位(colIdx) |
26 | jQuery.fn.rowspan = function(colIdx, colDepend) { |
27 | return this.each(function() { |
28 | var that; |
29 | var depend; |
30 | $('tr', this).each(function(row) { |
31 | var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this); |
32 | var dependCol = $('td:eq(' + colDepend + '),th:eq(' + colDepend + ')', this); |
33 | if ((that != null) && (depend != null) && ($(thisRow).html() == $(that).html()) && ($(depend).html() == $(dependCol).html())) { |
34 | rowspan = $(that).attr("rowSpan"); |
35 | if (rowspan == undefined) { |
36 | $(that).attr("rowSpan", 1); |
37 | rowspan = $(that).attr("rowSpan"); |
38 | } |
39 | rowspan = Number(rowspan) + 1; |
40 | $(that).attr("rowSpan", rowspan); |
41 | $(thisRow).remove(); ////$(thisRow).hide(); |
42 |
43 | } else { |
44 | that = thisRow; |
45 | depend = dependCol; |
46 | } |
47 | that = (that == null) ? thisRow : that; |
48 | depend = (depend == null) ? dependCol : depend; |
49 | }); |
50 | }); |
51 | } |
52 |
53 | ////合併左右欄位 |
54 | jQuery.fn.colspan = function(rowIdx) { |
55 | return this.each(function() { |
56 | var that; |
57 | $('tr', this).filter(":eq(" + rowIdx + ")").each(function(row) { |
58 | $(this).find('th,td').each(function(col) { |
59 | if ((that != null) && ($(this).html() == $(that).html())) { |
60 | colspan = $(that).attr("colSpan"); |
61 | if (colspan == undefined) { |
62 | $(that).attr("colSpan", 1); |
63 | colspan = $(that).attr("colSpan"); |
64 | } |
65 | colspan = Number(colspan) + 1; |
66 | $(that).attr("colSpan", colspan); |
67 | $(this).remove(); |
68 | } else { |
69 | that = this; |
70 | } |
71 | that = (that == null) ? this : that; |
72 | }); |
73 | }); |
74 | }); |
75 | } |
01 | <table id="table1" border="1" class="tbspan"> |
02 | <tr> |
03 | <td>A</td> |
04 | <td>B</td> |
05 | <td>B</td> |
06 | <td>C</td> |
07 | <td>C</td> |
08 | </tr> |
09 | <tr> |
10 | <td>1</td> |
11 | <td>2</td> |
12 | <td>3</td> |
13 | <td>4</td> |
14 | <td>5</td> |
15 | </tr> |
16 | <tr> |
17 | <td>1</td> |
18 | <td>2</td> |
19 | <td>3</td> |
20 | <td>4</td> |
21 | <td>5</td> |
22 | </tr> |
23 | <tr> |
24 | <td>2</td> |
25 | <td>2</td> |
26 | <td>3</td> |
27 | <td>4</td> |
28 | <td>5</td> |
29 | </tr> |
30 | <tr> |
31 | <td>2</td> |
32 | <td>2</td> |
33 | <td>3</td> |
34 | <td>4</td> |
35 | <td>5</td> |
36 | </tr> |
37 | </table> |
1 | $(function() { |
2 | $('.tbspan').rowspan(0); |
3 | $('.tbspan').rowspan(1); |
4 | $('.tbspan').colspan(0); |
5 | }); |
1 | $(function() { |
2 | $('.tbspan').rowspan(3,0); |
3 | $('.tbspan').rowspan(0); |
4 | $('.tbspan').rowspan(1); |
5 | $('.tbspan').colspan(0); |
6 | }); |
01 | ////合併上下欄位(colIdx) |
02 | jQuery.fn.rowspan = function(colIdx) { |
03 | return this.each(function() { |
04 | var that; |
05 | $('tr', this).each(function(row) { |
06 | var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this); |
07 | if ((that != null) && ($(thisRow).html() == $(that).html())) { |
08 | rowspan = $(that).attr("rowSpan"); |
09 | if (rowspan == undefined) { |
10 | $(that).attr("rowSpan", 1); |
11 | rowspan = $(that).attr("rowSpan"); |
12 | } |
13 | rowspan = Number(rowspan) + 1; |
14 | $(that).attr("rowSpan", rowspan); |
15 | $(thisRow).remove(); ////$(thisRow).hide(); |
16 | } else { |
17 | that = thisRow; |
18 | } |
19 | that = (that == null) ? thisRow : that; |
20 | }); |
21 | alert('1'); |
22 | }); |
23 | } |
24 |
25 | ////當指定欄位(colDepend)值相同時,才合併欄位(colIdx) |
26 | jQuery.fn.rowspan = function(colIdx, colDepend) { |
27 | return this.each(function() { |
28 | var that; |
29 | var depend; |
30 | $('tr', this).each(function(row) { |
31 | var thisRow = $('td:eq(' + colIdx + '),th:eq(' + colIdx + ')', this); |
32 | var dependCol = $('td:eq(' + colDepend + '),th:eq(' + colDepend + ')', this); |
33 | if ((that != null) && (depend != null) && ($(thisRow).html() == $(that).html()) && ($(depend).html() == $(dependCol).html())) { |
34 | rowspan = $(that).attr("rowSpan"); |
35 | if (rowspan == undefined) { |
36 | $(that).attr("rowSpan", 1); |
37 | rowspan = $(that).attr("rowSpan"); |
38 | } |
39 | rowspan = Number(rowspan) + 1; |
40 | $(that).attr("rowSpan", rowspan); |
41 | $(thisRow).remove(); ////$(thisRow).hide(); |
42 |
43 | } else { |
44 | that = thisRow; |
45 | depend = dependCol; |
46 | } |
47 | that = (that == null) ? thisRow : that; |
48 | depend = (depend == null) ? dependCol : depend; |
49 | }); |
50 | }); |
51 | } |
52 |
53 | ////合併左右欄位 |
54 | jQuery.fn.colspan = function(rowIdx) { |
55 | return this.each(function() { |
56 | var that; |
57 | $('tr', this).filter(":eq(" + rowIdx + ")").each(function(row) { |
58 | $(this).find('th,td').each(function(col) { |
59 | if ((that != null) && ($(this).html() == $(that).html())) { |
60 | colspan = $(that).attr("colSpan"); |
61 | if (colspan == undefined) { |
62 | $(that).attr("colSpan", 1); |
63 | colspan = $(that).attr("colSpan"); |
64 | } |
65 | colspan = Number(colspan) + 1; |
66 | $(that).attr("colSpan", colspan); |
67 | $(this).remove(); |
68 | } else { |
69 | that = this; |
70 | } |
71 | that = (that == null) ? this : that; |
72 | }); |
73 | }); |
74 | }); |
75 | } |
01 | <table id="table1" border="1" class="tbspan"> |
02 | <tr> |
03 | <td>A</td> |
04 | <td>B</td> |
05 | <td>B</td> |
06 | <td>C</td> |
07 | <td>C</td> |
08 | </tr> |
09 | <tr> |
10 | <td>1</td> |
11 | <td>2</td> |
12 | <td>3</td> |
13 | <td>4</td> |
14 | <td>5</td> |
15 | </tr> |
16 | <tr> |
17 | <td>1</td> |
18 | <td>2</td> |
19 | <td>3</td> |
20 | <td>4</td> |
21 | <td>5</td> |
22 | </tr> |
23 | <tr> |
24 | <td>2</td> |
25 | <td>2</td> |
26 | <td>3</td> |
27 | <td>4</td> |
28 | <td>5</td> |
29 | </tr> |
30 | <tr> |
31 | <td>2</td> |
32 | <td>2</td> |
33 | <td>3</td> |
34 | <td>4</td> |
35 | <td>5</td> |
36 | </tr> |
37 | </table> |
1 | $(function() { |
2 | $('.tbspan').rowspan(0); |
3 | $('.tbspan').rowspan(1); |
4 | $('.tbspan').colspan(0); |
5 | }); |
1 | $(function() { |
2 | $('.tbspan').rowspan(3,0); |
3 | $('.tbspan').rowspan(0); |
4 | $('.tbspan').rowspan(1); |
5 | $('.tbspan').colspan(0); |
6 | }); |
通信人家园 (https://www.txrjy.com/) | Powered by C114 |