javascript 表格左右收缩 时间:2020-05-12 人气:0 左右收缩表格 <script language="JavaScript" type="text/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;m<=minNumber;m++) { colObjs(m).style.display="none"; } for(var n=minNumber+1;nminNumber+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"; } } } </script> col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 <script>tableOnLoad();</script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容