js动态生成表,带有滚动条
来源:互联网 发布:示波器的使用 实验数据 编辑:程序博客网 时间:2024/06/08 14:11
js动态生成表,带有滚动条,调用ini()函数
<script language="javascript">
String.prototype.Trim = function()
...{
return this.replace(/(^s*)|(s*$)/g, "");
}
function hideserver()...{
if(document.getElementById("showtable").style.display=="block")...{
document.getElementById("showtable").style.display="none";
document.getElementById("showtable").deleteCaption();
document.getElementById("showtable").removeNode();
document.getElementById("showtable").deleteTHead();
document.getElementById("showtable").deleteTFoot();
}
else...{
document.getElementById("showtable").deleteCaption();
document.getElementById("showtable").removeNode();
document.getElementById("showtable").deleteTHead();
document.getElementById("showtable").deleteTFoot();
}
}
function check_data(port,name)...{
//alert(port);
document.getElementById("ServerName").value=name;
document.getElementById("ServerPort").value=port;
hideserver();
}
function init()...{
theT=createTable("所有业务",[" 端口号:100","业务名称:150","业务组:300"]);
//参数说明:createTable(strCaption,colHeads)
//strCaption 标题
//colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
var arrport= new Array();
var arrname= new Array();
var arrgroup= new Array();
var allport="1,2,3,5,6,7,8,9";
var allname="qqq,qqwrq,qrqr,tqtqt,qwqwrwqr,qwrqwr,qwrqwr,qrqwr,qwrqwr";
var allgroup="qwe,q111,334,fff,fff,ggg,ggh,hhh,vvvv";
//alert(allvalue);
arrport=allport.split(",");
arrname=allname.split(",");
arrgroup=allgroup.split(",");
for(var i=0;i<arrport.length-1;i++)...{
theR=theT.insertRow();
theC=theR.insertCell();
theC.innerText=arrport[i];
theC=theR.insertCell();
theC.innerHTML="<a href=javascript:check_data('"+arrport[i]+"','"+arrname[i].replace(/ /g,' ')+"')>"+arrname[i]+"</a>";
theC=theR.insertCell();
theC.innerText=arrgroup[i];
//for(var j=0;j<3;j++){
// theC=theR.insertCell();
// theC.innerText=arrdata[i][j];
//}
}
}
function createTable(strCaption,colHeads)...{
//参数说明:colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
//生成表格
oTable=document.createElement("table");
oTable.id="showtable";
document.body.insertBefore(oTable);
//设置class
oTable.className="table0";
oTable.style.display="block";
with(oTable.style)...{
tableLayout="fixed";
borderCollapse="collapse"
borderSpacing="0px";
}
//设置变量
oTCaption=oTable.createCaption();
oTHead=oTable.createTHead();
oTFoot=oTable.createTFoot();
//生成标题
oTCaption.style.backgroundColor ="#f6f6f6";
oTCaption.innerText=strCaption;
//设置列宽
oTHead.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadName=colHeads[i].split(":")[0];
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTHead.rows[0].insertCell();
theCell.style.width=tHeadWidth;
}
theCell=oTHead.rows[0].insertCell();
theCell.width=20;
oTHead.rows[0].style.display="none";
//生成表头
oTHead.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadName=colHeads[i].split(":")[0];
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTHead.rows[1].insertCell();
theCell.bgcolor="#ff0000";
theCell.innerText=tHeadName;
theCell.style.width=tHeadWidth;
}
theCell=oTHead.rows[1].insertCell();
theCell.innerHTML="<a href='javascript:hideserver()'>×</a>";
theCell.width=24;
//生成表脚
oTFoot.insertRow();
theCell=oTFoot.rows[0].insertCell();
theCell.innerHTML="";
theCell=oTFoot.rows[0].insertCell();
theCell.colSpan=colHeads.length-1;
theCell=oTFoot.rows[0].insertCell();
theCell.width=20;
//生成主体
oTable.all.tags("Tbody")[0].insertRow();
theCell=oTable.all.tags("Tbody")[0].rows[0].insertCell();
theCell.colSpan=colHeads.length+1;
oMain=document.createElement("DIV");
theCell.insertBefore(oMain);
with(oMain.style)...{
width="100%";
height="100%";
overflowY="auto";
overflowX="hidden";
margin="0px";
marginLeft="-1px";
}
oTBody=document.createElement("table");
oMain.insertBefore(oTBody);
oTable.oTBody=oTBody;
//禁止选择
oTCaption.onselectstart=oTHead.onselectstart=oTFoot.onselectstart=function()...{return(false);}
//设置class
oTBody.className="table1";
with(oTBody.style)...{
width=oTable.offsetWidth-15;
tableLayout="fixed";
borderCollapse="collapse"
borderSpacing="0px";
padding="0px";
margin="0px";
}
//初始化列宽
oTBody.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTBody.rows[0].insertCell();
theCell.style.width=tHeadWidth;
}
oTBody.rows[0].style.display="none";
return(oTBody);
}
function insertRow()...{
var intL=oTBody.rows.length;
theRow=oTBody.insertRow();
theRow.index=intL;
theRow.onmouseover=rowOnMouseOver;
theRow.onmouseout=rowOnMouseOut;
theRow.onclick=rowOnClick;
for(var i=0;i<colHeads.length;i++)...{
theCell=theRow.insertCell();
theCell.tabIndex=0;
theCell.hideFocus=true;
theCell.style.backgroundColor="#FF0000";
theCell.colIndex=i;
theCell.onmouseover=function()...{this.focus();};
theCell.onmouseout=cellOnBlur;
theCell.onfocus=cellOnFocus;
theCell.onblur=cellOnBlur;
}
theRow.cells[0].innerText=strGroup?strGroup:"ROOT";
theRow.cells[1].innerText=strName?strName:"Untitled Document.";
theRow.cells[2].innerText=strURL?strURL:"Unspecified URL";
theRow.cells[3].innerHTML=strVisited?"Yes".fontcolor("red"):"Unknow";
theRow.cells[4].innerHTML=strModify?"Yes".fontcolor("red"):"No".fontcolor("Green");
theRow.cells[5].innerHTML="Delete".fontcolor("red");
}
</script>
String.prototype.Trim = function()
...{
return this.replace(/(^s*)|(s*$)/g, "");
}
function hideserver()...{
if(document.getElementById("showtable").style.display=="block")...{
document.getElementById("showtable").style.display="none";
document.getElementById("showtable").deleteCaption();
document.getElementById("showtable").removeNode();
document.getElementById("showtable").deleteTHead();
document.getElementById("showtable").deleteTFoot();
}
else...{
document.getElementById("showtable").deleteCaption();
document.getElementById("showtable").removeNode();
document.getElementById("showtable").deleteTHead();
document.getElementById("showtable").deleteTFoot();
}
}
function check_data(port,name)...{
//alert(port);
document.getElementById("ServerName").value=name;
document.getElementById("ServerPort").value=port;
hideserver();
}
function init()...{
theT=createTable("所有业务",[" 端口号:100","业务名称:150","业务组:300"]);
//参数说明:createTable(strCaption,colHeads)
//strCaption 标题
//colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
var arrport= new Array();
var arrname= new Array();
var arrgroup= new Array();
var allport="1,2,3,5,6,7,8,9";
var allname="qqq,qqwrq,qrqr,tqtqt,qwqwrwqr,qwrqwr,qwrqwr,qrqwr,qwrqwr";
var allgroup="qwe,q111,334,fff,fff,ggg,ggh,hhh,vvvv";
//alert(allvalue);
arrport=allport.split(",");
arrname=allname.split(",");
arrgroup=allgroup.split(",");
for(var i=0;i<arrport.length-1;i++)...{
theR=theT.insertRow();
theC=theR.insertCell();
theC.innerText=arrport[i];
theC=theR.insertCell();
theC.innerHTML="<a href=javascript:check_data('"+arrport[i]+"','"+arrname[i].replace(/ /g,' ')+"')>"+arrname[i]+"</a>";
theC=theR.insertCell();
theC.innerText=arrgroup[i];
//for(var j=0;j<3;j++){
// theC=theR.insertCell();
// theC.innerText=arrdata[i][j];
//}
}
}
function createTable(strCaption,colHeads)...{
//参数说明:colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
//生成表格
oTable=document.createElement("table");
oTable.id="showtable";
document.body.insertBefore(oTable);
//设置class
oTable.className="table0";
oTable.style.display="block";
with(oTable.style)...{
tableLayout="fixed";
borderCollapse="collapse"
borderSpacing="0px";
}
//设置变量
oTCaption=oTable.createCaption();
oTHead=oTable.createTHead();
oTFoot=oTable.createTFoot();
//生成标题
oTCaption.style.backgroundColor ="#f6f6f6";
oTCaption.innerText=strCaption;
//设置列宽
oTHead.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadName=colHeads[i].split(":")[0];
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTHead.rows[0].insertCell();
theCell.style.width=tHeadWidth;
}
theCell=oTHead.rows[0].insertCell();
theCell.width=20;
oTHead.rows[0].style.display="none";
//生成表头
oTHead.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadName=colHeads[i].split(":")[0];
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTHead.rows[1].insertCell();
theCell.bgcolor="#ff0000";
theCell.innerText=tHeadName;
theCell.style.width=tHeadWidth;
}
theCell=oTHead.rows[1].insertCell();
theCell.innerHTML="<a href='javascript:hideserver()'>×</a>";
theCell.width=24;
//生成表脚
oTFoot.insertRow();
theCell=oTFoot.rows[0].insertCell();
theCell.innerHTML="";
theCell=oTFoot.rows[0].insertCell();
theCell.colSpan=colHeads.length-1;
theCell=oTFoot.rows[0].insertCell();
theCell.width=20;
//生成主体
oTable.all.tags("Tbody")[0].insertRow();
theCell=oTable.all.tags("Tbody")[0].rows[0].insertCell();
theCell.colSpan=colHeads.length+1;
oMain=document.createElement("DIV");
theCell.insertBefore(oMain);
with(oMain.style)...{
width="100%";
height="100%";
overflowY="auto";
overflowX="hidden";
margin="0px";
marginLeft="-1px";
}
oTBody=document.createElement("table");
oMain.insertBefore(oTBody);
oTable.oTBody=oTBody;
//禁止选择
oTCaption.onselectstart=oTHead.onselectstart=oTFoot.onselectstart=function()...{return(false);}
//设置class
oTBody.className="table1";
with(oTBody.style)...{
width=oTable.offsetWidth-15;
tableLayout="fixed";
borderCollapse="collapse"
borderSpacing="0px";
padding="0px";
margin="0px";
}
//初始化列宽
oTBody.insertRow();
for(var i=0;i<colHeads.length;i++)...{
tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
theCell=oTBody.rows[0].insertCell();
theCell.style.width=tHeadWidth;
}
oTBody.rows[0].style.display="none";
return(oTBody);
}
function insertRow()...{
var intL=oTBody.rows.length;
theRow=oTBody.insertRow();
theRow.index=intL;
theRow.onmouseover=rowOnMouseOver;
theRow.onmouseout=rowOnMouseOut;
theRow.onclick=rowOnClick;
for(var i=0;i<colHeads.length;i++)...{
theCell=theRow.insertCell();
theCell.tabIndex=0;
theCell.hideFocus=true;
theCell.style.backgroundColor="#FF0000";
theCell.colIndex=i;
theCell.onmouseover=function()...{this.focus();};
theCell.onmouseout=cellOnBlur;
theCell.onfocus=cellOnFocus;
theCell.onblur=cellOnBlur;
}
theRow.cells[0].innerText=strGroup?strGroup:"ROOT";
theRow.cells[1].innerText=strName?strName:"Untitled Document.";
theRow.cells[2].innerText=strURL?strURL:"Unspecified URL";
theRow.cells[3].innerHTML=strVisited?"Yes".fontcolor("red"):"Unknow";
theRow.cells[4].innerHTML=strModify?"Yes".fontcolor("red"):"No".fontcolor("Green");
theRow.cells[5].innerHTML="Delete".fontcolor("red");
}
</script>
- js动态生成表,带有滚动条
- JS动态生成表格+表格高度滚动条
- js动态移动滚动条至底部
- js实现动态拖动滚动条效果
- 带有滚动条的textview
- js实现随滚动条滚动div位置动态变化
- WINFROM下带有自动滚动条截图
- 动态滚动条
- 加载动态滚动条
- js控制滚动条
- js滚动条
- js滚动条技巧
- 关于js滚动条
- js禁用滚动条
- js 模拟 滚动条
- js禁用滚动条
- js滚动条位置
- JS滚动条
- 如何给FLV文件加字幕
- COM组件设计与应用(九)IDispatch 接口 for vc6.0
- 我在遥望
- COM组件设计与应用(十)IDispatch 接口 for vc.net
- Linux C 函数参考之进程操作篇
- js动态生成表,带有滚动条
- 好东西大家分享: 怎么做程序员
- 如何做好一个垂直搜索引擎
- 在VB.NET中怎么样判断一个数组是不是为空?
- COM 组件设计与应用(十一)IDispatch 及双接口的调用
- js 显示你系统的日期和时间,超级简单
- QQ论坛在线G机程序
- 自画收集
- 好东西大家分享: 掌握复杂性的技巧-分解和规则