function swapNode(node1,node2)
{
var _parent1=node1.parentNode;
var _parent2=node2.parentNode;
var _t1=node1.nextSibling;
var _t2=node2.nextSibling;
if(_t1)
{
_parent1.insertBefore(node2,_t1);
}
else
{
_parent1.appendChild(node2);
}
if(_t2)
{
_parent2.insertBefore(node1,_t2);
}
else
{
_parent2.appendChild(node1);
}
}
/*根据表格的长度、列数、传入的掩码,显示表格的内容,每2个蜂房显示共用一个掩码;
注意这个传入的表格在tbody前有一行表头显示。
table, 表格的名字
dis, 显示的掩码,一个掩码对应一行中的两列
leng, 表格的长度
in_cells,表格的列,每行分的列数,必须是2的整数倍*/
function rotp_displayorHide(table, dis, leng, in_cells)
{
var oTab = document.getElementById(table);
var oTbody = oTab.tBodies[1];
var oRows = oTbody.rows;
var j = 0;
var k = 0;
var a = 0;
var oTd;
var arr = new Array();
/*根据列,算出行的分割*/
var out_rows = parseInt(in_cells/2);
for(i=0; i {
arr[i] = dis[i];
}
j =0;
for(i=0; i {
if (arr[i] == 0)
{
oTbody.rows[j].cells[k].style.display = "none";
oTbody.rows[j].cells[k+1].style.display = "none";
}
else
{
for(a=0; a {
if (arr[a] == 0)
{
swapNode(oTbody.rows[j].cells[k],oTbody.rows[parseInt(a/out_rows)].cells[(a%out_rows)*2]);
swapNode(oTbody.rows[j].cells[k+1],oTbody.rows[parseInt(a/out_rows)].cells[(a%out_rows)*2+1]);
arr[a] = 1;
arr[i] = 0;
break;
}
}
}
k+=2;
if (k == in_cells)
{
j++;
k = 0;
}
}
//去除不显示的行
for (i=0; i
{
if (0 == arr[i])
{
break;
}
}
var m;
var p;
var n = i;/*显示的cell个数*/
m = arr.length - i;/*隐藏的cell个数*/
/*恰好是整行*/
if (arr.length%out_rows == 0)
{
p = parseInt(arr.length/out_rows);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
else/*非整行*/
{
if (m%out_rows)/*隐藏的cell不是整数倍*/
{
p = parseInt((arr.length+out_rows-1)/out_rows);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
else/**/
{
p = parseInt((arr.length+out_rows-1)/out_rows);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
}
/*插入空cell*/
if (n%out_rows != 0)
{
for(var y=0; y<(out_rows-n%out_rows); y++)
{
oTbody.rows[parseInt(n/out_rows)].insertCell((n%out_rows+y)*2);
oTbody.rows[parseInt(n/out_rows)].insertCell((n%out_rows+y)*2+1);
}
}
//如果dis全为0,隐藏整个表单
for(i=0; i {
if (dis[i])
{
break;
}
}
if (i==leng)
{
oTab.style.display = "none";
}
}
/*这个适合1行4列,一个掩码代表2个cell(列)*/
function displayorHide(table, dis, leng)
{
var oTab = document.getElementById(table);
var oTbody = oTab.tBodies[1];
var oRows = oTbody.rows;
var j = 0;
var k = 0;
var a = 0;
var oTd;
var arr = new Array();
for(i=0; i {
arr[i] = dis[i];
}
j =0;
for(i=0; i {
if (arr[i] == 0)
{
oTbody.rows[j].cells[k].style.display = "none";
oTbody.rows[j].cells[k+1].style.display = "none";
}
else
{
for(a=0; a {
if (arr[a] == 0)
{
swapNode(oTbody.rows[j].cells[k],oTbody.rows[parseInt(a/2)].cells[(a%2)*2]);
swapNode(oTbody.rows[j].cells[k+1],oTbody.rows[parseInt(a/2)].cells[(a%2)*2+1]);
/*
newRow = oTbody.rows[j];
oldRow = oTbody.rows[parseInt(a/2)];
td1New = newRow.cells[k];//new
td1Old = oldRow.cells[(a%2)*2];//old
td2New = newRow.cells[k+1];//new
td2Old = oldRow.cells[(a%2)*2+1];//old
oldRow.insertBefore(newRow.cells[k], oldRow.cells[(a%2)*2]);
newRow.insertBefore(oldRow.cells[(a%2)*2+1], newRow.cells[k]);
oldRow.insertBefore(newRow.cells[k+1], oldRow.cells[(a%2)*2+1]);
if (i==leng-1)
{
newRow.appendChild(oldRow.cells[(a%2)*2+1+1]);
}
else if(k+1 == 1)
{
newRow.insertBefore(oldRow.cells[(a%2)*2+1+1], newRow.cells[k+1]);
}
else
{
newRow.appendChild(oldRow.cells[(a%2)*2+1+1]);
}*/
arr[a] = 1;
arr[i] = 0;
break;
}
}
}
k+=2;
if (k == 4)
{
j++;
k = 0;
}
}
//去除不显示的行
for (i=0; i
{
if (0 == arr[i])
{
break;
}
}
var m;
var p;
var n = i;
m = arr.length - i;
if (arr.length%2 == 0)
{
p = parseInt(arr.length/2);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
else
{
if (m%2)
{
p = parseInt((arr.length+1)/2);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
else
{
p = parseInt((arr.length+1)/2);
for (i=0; i {
oTbody.rows[p-i-1].style.display = "none";
}
}
}
if (n%2 != 0)
{
oTbody.rows[parseInt(n/2)].insertCell(2);
oTbody.rows[parseInt(n/2)].insertCell(3);
}
//如果dis全为0,隐藏整个表单
for(i=0; i {
if (dis[i])
{
break;
}
}
if (i==leng)
{
oTab.style.display = "none";
}
}
阅读(962) | 评论(0) | 转发(1) |