<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>合并表格</title>
<script>
///////////////////////////////////////////////
// 功能:合并表格
// 參數(shù):tb--需要合并的表格ID
// 參數(shù):colLength--需要對(duì)前幾列進(jìn)行合并,比如,
// 想合并前兩列,后面的數(shù)據(jù)列忽略合并,colLength應(yīng)為2
// 缺省表示對(duì)全部列合并
// data: 2005.11.6
///////////////////////////////////////////////
function uniteTable(tb,colLength){
// 檢查表格是否規(guī)整
if (!checkTable(tb)) return;
var i=0;
var j=0;
var rowCount=tb.rows.length; // 行數(shù)
var colCount=tb.rows[0].cells.length; // 列數(shù)
var obj1=null;
var obj2=null;
// 為每個(gè)單元格命名
for (i=0;i<rowCount;i++){
for (j=0;j<colCount;j++){
tb.rows[i].cells[j].id="tb__" + i.toString() + "_" + j.toString();
}
}
// 逐列檢查合并
for (i=0;i<colCount;i++){
if (i==colLength) return;
obj1=document.getElementById("tb__0_"+i.toString())
for (j=1;j<rowCount;j++){
obj2=document.getElementById("tb__"+j.toString()+"_"+i.toString());
if (obj1.innerText == obj2.innerText){
obj1.rowSpan++;
obj2.parentNode.removeChild(obj2);
}else{
obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString());
}
}
}
}
/////////////////////////////////////////
// 功能:檢查表格是否規(guī)整
// 參數(shù):tb--需要檢查的表格ID
// data: 2005.11.6
/////////////////////////////////////////
function checkTable(tb){
if (tb.rows.length==0) return false;
if (tb.rows[0].cells.length==0) return false;
for (var i=0;i<tb.rows.length;i++){
if (tb.rows[0].cells.length != tb.rows[i].cells.length) return false;
}
return true;
}
function SpanGrid(tabObj,colIndex) {
if(tabObj != null) {
var i,j;
var intSpan;
var strTemp;
for(var m = 0; m <colIndex; m++ ){
for(i = 0; i < tabObj.rows.length; i++) {
intSpan = 1;
strTemp = tabObj.rows[i].cells[m].innerText;
for(j = i + 1; j < tabObj.rows.length; j++) {
if(strTemp == tabObj.rows[j].cells[m].innerText) {
intSpan++;
tabObj.rows[i].cells[m].rowSpan = intSpan;
tabObj.rows[j].cells[m].style.display = "none";
} else {
break;
}
}
i = j - 1;
}
}
}
}
function SpanGrid2(tabObj,colIndex) {
if(tabObj != null) {
var i,j;
var intSpan;
var strTemp;
for(i = 0; i < tabObj.rows.length; i++) {
intSpan = 1;
strTemp = tabObj.rows[i].cells[m].innerText;
for(j = i + 1; j < tabObj.rows.length; j++) {
if(strTemp == tabObj.rows[j].cells[m].innerText) {
intSpan++;
tabObj.rows[i].cells[m].rowSpan = intSpan;
tabObj.rows[j].cells[m].style.display = "none";
} else {
break;
}
}
i = j - 1;
}
}
}
</script>
</head>
<body>
<table width="400" border="1" id="table1">
<tr>
<td>a</td>
<td>for</td>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>a</td>
<td>for</td>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>300</td>
<td>240</td>
</tr>
<tr>
<td>a</td>
<td>if</td>
<td>320</td>
<td>320</td>
</tr>
</table>
<br>
<input type="button" value="合并表格" onClick="SpanGrid(table1,2)">
</body>
</html>
只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
|
||
相關(guān)文章:
|
||
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
28 | 29 | 30 | 1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
26 | 27 | 28 | 29 | 30 | 31 | 1 | |||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
常用鏈接
留言簿(4)
隨筆分類(lèi)
- AJAX(2)
- CSS(4)
- freemarker
- hibernate
- HTML/XML(6)
- Jasper Report(1)
- javascript(26)
- java編程(20)
- JSP基礎(chǔ)(4)
- oracle(18)
- spring(1)
- struts(3)
- 其他(13)
- 架構(gòu)設(shè)計(jì)(2)
- 編碼規(guī)范
- 設(shè)計(jì)模式(1)
隨筆檔案
- 2012年8月 (1)
- 2011年4月 (2)
- 2011年2月 (2)
- 2010年8月 (9)
- 2010年7月 (1)
- 2009年11月 (2)
- 2009年10月 (3)
- 2009年9月 (11)
- 2009年8月 (4)
- 2009年6月 (7)
- 2008年12月 (1)
- 2008年10月 (3)
- 2008年8月 (4)
- 2008年7月 (1)
- 2008年6月 (2)
- 2008年4月 (2)
- 2008年3月 (1)
- 2008年2月 (1)
- 2008年1月 (3)
- 2007年12月 (15)
- 2007年11月 (14)
- 2007年10月 (12)
- 2007年8月 (2)
搜索
最新評(píng)論

- 1.?re: Blowfish加密算法之Java實(shí)現(xiàn)[未登錄](méi)
- 這個(gè)有c語(yǔ)言版沒(méi)
- --小丸子
- 2.?re: SSH實(shí)現(xiàn)分頁(yè)
-
我和上面的一樣,你的分頁(yè)很簡(jiǎn)單,能否發(fā)一份給我呢?
我的QQ郵箱是511775600@qq.com - --瞇露
- 3.?re: String.equals()和String.equalsIgnoreCase()的區(qū)別
- 觀(guān)后感矛
- --和規(guī)劃局
- 4.?re: 時(shí)間控件(可含時(shí)分秒)
- thank you 樓主
- --yaoj
- 5.?re: 時(shí)間控件(可含時(shí)分秒)
- 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
- --末日風(fēng)情