javascript 表格左右收缩
左右收缩表格
function tableOnLoad()
{
var tableObj=document.getElementById("testTable");
var colNumber=tableObj.rows.item(0).cells.length;
var colObjs=tableObj.getElementsByTagName("td");
if(colNumber>5)
{
for(var i=5;i5){
for(var m=0;mminNumber+5;j--)
{
colObjs(j).style.display="none";
}
}
}
function tableRightRetract()
{
var tableObj=document.getElementById("testTable");
var colNumber=tableObj.rows.item(0).cells.length;
var colObjs=tableObj.getElementsByTagName("td");
//minNumber of column of which display style is none
var maxNumber=colNumber-1;
for(var i=colNumber-1;i>=0;i--)
{
if(colObjs(i).style.display!="none")
{
maxNumber=i;
break;
}
}
if(maxNumber>=5 && colNumber>5){
for(var m=colNumber-1;m>=maxNumber;m--)
{
colObjs(m).style.display="none";
}
for(var n=maxNumber-1;n>maxNumber-1-5;n--)
{
colObjs(n).style.display="";
}
for(var j=maxNumber-1-5-1;j>=0;j--)
{
colObjs(j).style.display="none";
}
}
}
|
tableOnLoad();
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]