/************* layer function ******************/
function makeLayer( idStr ) {
this.idStr = idStr;
if(bw.ns4)this.obj=document.layers[idStr];
else if (bw.ns6) this.obj = document.getElementById(idStr);
else this.obj=eval('document.all.'+idStr);
if (bw.ns6) this.css=this.obj.style;
else if (bw.ns) this.css=this.obj;
else this.css=this.obj.style;
this.x = getLayerX(this.idStr);
this.y = getLayerY(this.idStr);
this.moveTo=lib_moveTo;
return (this);
}
function lib_moveTo(x,y){
this.x=x!=''?x:this.x;
this.y=y!=''?y:this.y;
this.css.left=this.x;
this.css.top=this.y
}
function getLayerX( ID ) {
if (bw.ns6) return(parseInt(document.getElementById(ID).style.left));
else if (bw.ns) return(document.layers[ID].left);
else return(document.all[ID].offsetLeft);
}
function getLayerY( ID ) {
if (bw.ns6) return(parseInt(document.getElementById(ID).style.top));
else if (bw.ns) return(document.layers[ID].top);
else return(document.all[ID].offsetTop);
}
//-->
</SCRIPT>
</HEAD><BODY onload="dragInit()">
<SCRIPT LANGUAGE="JavaScript">
<!--//注意不要把顺序颠倒
oExcel=new TExcel('oExcel');
with(oExcel){
addField('职级','描述','ffgg','efew','egwg','人','合共工资','俭这%');//用于创建字段
addRecord('llrock','llrock','i love you i love you ')//用于创建纪录
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ') makeStyle();
makeCode();
document.write(htmlcode);
getObj();
arrange();
}
//-->
</SCRIPT>
</BODY>
</HTML>
昨天有个人要能够拖懂td的东西,做了好久,结果发现用table做太难了,td的width和height太难控制,结果想了想就用div做了,发现听想table的,不信你看看,hehe,昨天失恋放分,今天就放代码,其实这个东西没什么用,不过代替table 倒也不错,或者在结些函数让她一次性提交大量数据到database,hehe
function makeLayer( idStr ) {
this.idStr = idStr;
if(bw.ns4)this.obj=document.layers[idStr];
else if (bw.ns6) this.obj = document.getElementById(idStr);
else this.obj=eval('document.all.'+idStr);
if (bw.ns6) this.css=this.obj.style;
else if (bw.ns) this.css=this.obj;
else this.css=this.obj.style;
this.x = getLayerX(this.idStr);
this.y = getLayerY(this.idStr);
this.moveTo=lib_moveTo;
return (this);
}
function lib_moveTo(x,y){
this.x=x!=''?x:this.x;
this.y=y!=''?y:this.y;
this.css.left=this.x;
this.css.top=this.y
}
function getLayerX( ID ) {
if (bw.ns6) return(parseInt(document.getElementById(ID).style.left));
else if (bw.ns) return(document.layers[ID].left);
else return(document.all[ID].offsetLeft);
}
function getLayerY( ID ) {
if (bw.ns6) return(parseInt(document.getElementById(ID).style.top));
else if (bw.ns) return(document.layers[ID].top);
else return(document.all[ID].offsetTop);
}
//-->
</SCRIPT>
</HEAD><BODY onload="dragInit()">
<SCRIPT LANGUAGE="JavaScript">
<!--//注意不要把顺序颠倒
oExcel=new TExcel('oExcel');
with(oExcel){
addField('职级','描述','ffgg','efew','egwg','人','合共工资','俭这%');//用于创建字段
addRecord('llrock','llrock','i love you i love you ')//用于创建纪录
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ')
addRecord('llrock','llrock','i love you i love you ') makeStyle();
makeCode();
document.write(htmlcode);
getObj();
arrange();
}
//-->
</SCRIPT>
</BODY>
</HTML>
昨天有个人要能够拖懂td的东西,做了好久,结果发现用table做太难了,td的width和height太难控制,结果想了想就用div做了,发现听想table的,不信你看看,hehe,昨天失恋放分,今天就放代码,其实这个东西没什么用,不过代替table 倒也不错,或者在结些函数让她一次性提交大量数据到database,hehe
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
table-layout: fixed;
}.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
word-break:break-all;
}
</style>
<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">
<TR>
<TD width="100" class="tabletitleTD" >标题1</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="100" class="tabletitleTD" >标题2</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" class="tabletitleTD" >标题3</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="50" class="tabletitleTD" >标题4</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" bgcolor="#0099FF" class="tabletitleTD" >rerewr</TD>
<!-- <td width="150" height="9" align="center" class="tabletitleTD" >职级</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" >描述</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d3 >人头总数</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d4>合共工资</td>
<td width="1" rowspan="2"class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d5>涨幅 %</td>-->
</TR>
<TR>
<TD class="tt">123</TD>
<TD width="100" class="tt">123</TD>
<TD width="200" class="tt" >3463464reyhdytwru868w568</TD>
<TD width="50" class="tt">66</TD>
<TD width="200" class="tt">88</TD>
</TR>
<TR>
<TD height="20" class="tt">123</TD>
<TD width="100" class="tt">111</TD>
<TD width="200" class="tt">44</TD>
<TD width="50" class="tt">77</TD>
<TD width="200" class="tt">iiii</TD>
</TR>
<TR>
<TD class="tt">46</TD>
<TD width="100" class="tt">5645</TD>
<TD width="200" class="tt">757</TD>
<TD width="50" class="tt">757</TD>
<TD width="200" class="tt">456</TD>
</TR>
</TABLE>
这个可以让行字自动折行,但我不知它为什么拉开的时候只能到原使初定列宽。而乘下的就不能跳回一行。请指教。
<style>
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
}.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
}
</style>
<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">
<TR>
<TD width="100" class="tabletitleTD" >标题1</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="100" class="tabletitleTD" >标题2</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" class="tabletitleTD" >标题3</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="50" class="tabletitleTD" >标题4</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" bgcolor="#0099FF" class="tabletitleTD" >rerewr</TD>
<!-- <td width="150" height="9" align="center" class="tabletitleTD" >职级</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" >描述</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d3 >人头总数</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d4>合共工资</td>
<td width="1" rowspan="2"class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d5>涨幅 %</td>-->
</TR>
<TR>
<TD class="tt">123</TD>
<TD width="100" class="tt">123</TD>
<TD width="200" class="tt" >3463464reyhdytwru868w568</TD>
<TD width="50" class="tt">66</TD>
<TD width="200" class="tt">88</TD>
</TR>
<TR>
<TD height="20" class="tt">123</TD>
<TD width="100" class="tt">111</TD>
<TD width="200" class="tt">44</TD>
<TD width="50" class="tt">77</TD>
<TD width="200" class="tt">iiii</TD>
</TR>
<TR>
<TD class="tt">46</TD>
<TD width="100" class="tt">5645</TD>
<TD width="200" class="tt">757</TD>
<TD width="50" class="tt">757</TD>
<TD width="200" class="tt">456</TD>
</TR>
</TABLE>
我理解你的意思:你希望想excel那样列宽可以任意大是吗?
好吧,我就把它做成excel,晚上来这里取代码!
事实上table比div速度慢,虽然table有更多的样式,这也可以模仿,除了点划线边框很难模访(可以结合图片),
<style>
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
}
.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
}
.myscroll{FONT-SIZE: 12px;SCROLLBAR-HIGHLIGHT-COLOR: #FFFFFF;SCROLLBAR-SHADOW-COLOR: #e1e1e1;SCROLLBAR-3DLIGHT-COLOR: #e1e1e1;SCROLLBAR-TRACK-COLOR: white; SCROLLBAR-DARKSHADOW-COLOR: white; scrollbar-Base-Color: white; scrollbar-arrow-Color:}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function TDrag(){
this.x1=null;
this.x2=null;
this.obj=null;
this.tableW=null;
this.tdW=null;
this.table=null;
this.targetTD=null;
}
function check(){
var ok=false;
if(!oDrag.obj){ok=false;return ok}
}
function getTdSid(sid){
var targetSID=sid-1;
while(document.all[targetSID].tagName!='TD'){targetSID--}
return targetSID
}
function mDown(){
oDrag.obj=window.event.srcElement;
if(oDrag.obj.tagName=='TD'&&oDrag.obj.rowSpan!=1){
var targetSID=getTdSid(event.srcElement.sourceIndex);
oDrag.targetTD=document.all[targetSID];
oDrag.table=event.srcElement.parentElement.parentElement.parentElement;
oDrag.tableW=table.clientWidth;
oDrag.x1=event.x
}else{
oDrag.obj=null;
return false
}
}
function mMove(){
if(!oDrag.obj)return false;
try{
if(window.event.x>=(MainBG.offsetLeft+MainBG.clientWidth))return false;
oDrag.x2=event.x;
var dW=oDrag.x2-oDrag.x1;
oDrag.targetTD.style.width=oDrag.targetTD.clientWidth+dW
//if(dW>=0)
oDrag.table.style.width=dW+oDrag.tableW;//------------>!!!
}
catch(x){}
}
function mUp(){
oDrag.obj=null;
}
function refresh(){
var table=TableBG.children[0]
TableBG.style.width=table.clientWidth;
TableBG.style.height=table.clientHeight;
MainBG.style.width=(TableBG.clientHright>=500)?500:TableBG.clientWidth;
MainBG.style.height=(TableBG.clientHright>=500)?500:TableBG.clientHeight+16;//默认,高度超过500px使用滚动}
function dragInit(){
oDrag=new TDrag();
document.onmousedown = mDown
document.onmousemove = mMove
document.onmouseup = mUp;
}
//-->
</SCRIPT>
<div id="MainBG" style="position:absolute; left:100px; top:180px; z-index:1; ;border: 1px none #000000;overflow:auto;" class=myscroll>
<div id="TableBG" style="position:absolute; left:0px; top:0px; width:500px; height:277px; z-index:2; border: 1px none #000000">
<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">
<TR>
<TD width="100" class="tabletitleTD" ><div style="overflow:hidden">标题1</div></TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="100" class="tabletitleTD" ><div style="overflow:hidden">标题1</div></TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" class="tabletitleTD" ><div style="overflow:hidden">标题1</div></TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="50" class="tabletitleTD" ><div style="overflow:hidden">标题1</div></TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" bgcolor="#0099FF" class="tabletitleTD" >rerewr</TD>
<!-- <td width="150" height="9" align="center" class="tabletitleTD" >职级</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" >描述</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d3 >人头总数</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d4>合共工资</td>
<td width="1" rowspan="2"class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d5>涨幅 %</td>-->
</TR>
<TR>
<TD class="tt" style="overflow:hidden">标题1</TD>
<TD width="100" class="tt">123</TD>
<TD width="200" class="tt" >3463464reyhdytwru868w568</TD>
<TD width="50" class="tt">66</TD>
<TD width="200" class="tt">88</TD>
</TR>
<TR>
<TD height="20" class="tt">123</TD>
<TD width="100" class="tt">111</TD>
<TD width="200" class="tt">44</TD>
<TD width="50" class="tt">77</TD>
<TD width="200" class="tt">iiii</TD>
</TR>
<TR>
<TD class="tt">46</TD>
<TD width="100" class="tt">5645</TD>
<TD width="200" class="tt">757</TD>
<TD width="50" class="tt">757</TD>
<TD width="200" class="tt">456</TD>
</TR>
</TABLE> </div>
</div><SCRIPT LANGUAGE="JavaScript">
<!--
dragInit()
refresh()//-->
</SCRIPT>
这是你要得用table的,table的真的很难控制,其实我说用div就是为了通过数据库传入数据,我觉的非常方便,因为所有的代码我都是由javascript动态生成的,所以可以任意改变,但是由于table结构复杂,用javascrit生成麻烦,所以我从来不用table。我不明白你的最后一格向外申展是什么意思,是不是就是table宽度变大,还是用scrollbar控制
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style>
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
}
.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
}
.myscroll{FONT-SIZE: 12px;SCROLLBAR-HIGHLIGHT-COLOR: #FFFFFF;SCROLLBAR-SHADOW-COLOR: #e1e1e1;SCROLLBAR-3DLIGHT-COLOR: #e1e1e1;SCROLLBAR-TRACK-COLOR: white; SCROLLBAR-DARKSHADOW-COLOR: white; scrollbar-Base-Color: white; scrollbar-arrow-Color:}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function TTable(name){
this.name=name;
this.cols=new Array();
this.rows=new Array();
this.items=new Array();
this.colcount=0;//实际是列输减一
this.rowcount=0;
this.data=new Array();
//style
this.width=100;//colum width
this.bgc="#e7e7e7";
this.fontfamily="tahoma,arial,helvetica";
//method
this.addData=addData;
this.trimData=trimData;
this.create=create;
this.display=display;
this.refresh=refresh;
}
function TItem(owner,name,data,rindex,cindex,width,bgc,ftc){
this.owner=owner;
this.name=name;
this.data=data;
this.rindex=rindex;
this.cindex=cindex;
this.width=width||owner.width;
this.bgc=bgc||owner.bgc;
this.htmlcode=!rindex?'\n<TD width="100" class="tabletitleTD" >'+data+'</TD>\n<TD width="2" rowspan="'+owner.colcount+'" class="tdwbar" ></TD>':'\n<TD class="tt">'+data+'</TD>';
}function addData(){
var arg=addData.arguments;
var len=arg.length;
this.colcount=Math.max(this.colcount,len);
var tmpdata=new Array();
for(i=0;i<this.colcount;i++){
tmpdata[i]=!arg[i]?'':arg[i];
}
this.data[this.data.length]=tmpdata;
}
function trimData(){
for(i=0;i<this.data.length;i++){
for(j=0;j<this.colcount;j++){
this.data[i][j]=!this.data[i][j]?' ':this.data[i][j];
}
}
}
function create(){
for(i=0;i<this.data.length;i++){
this.items[i]=new Array;
for(j=0;j<this.colcount;j++){
this.items[i][j]=new TItem(this,this.data[i][j],this.data[i][j],i,j)
}
}
}
function display(){
this.htmlcode='';
this.htmlcode+='\n<div id="MainBG" style="position:absolute; left:100px; top:180px; z-index:1; ;border: 1px none #000000;overflow:auto;" class=myscroll>'
+'\n<div id="TableBG" style="position:absolute; left:0px; top:0px; z-index:2; border: 1px none #000000">'
+'\n<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">'; for(i=0;i<this.data.length;i++){
this.htmlcode+='\n<tr>';
for(j=0;j<this.colcount;j++){
this.htmlcode+=this.items[i][j].htmlcode;
}
this.htmlcode+='\n</tr>';
}
this.htmlcode+='</table></div></div>';
// alert(this.htmlcode)
document.write(this.htmlcode)
}
/******************* drag function ************************/
function TDrag(){
this.x1=null;
this.x2=null;
this.obj=null;
this.tableW=null;
this.tdW=null;
this.table=null;
this.targetTD=null;
}
function getTdSid(sid){
var targetSID=sid-1;
while(document.all[targetSID].tagName!='TD'){targetSID--}
return targetSID
}
function mDown(){
oDrag.obj=window.event.srcElement;
if(oDrag.obj.tagName=='TD'&&oDrag.obj.rowSpan!=1){
document.body.style.cursor="e-resize";
var targetSID=getTdSid(event.srcElement.sourceIndex);
oDrag.targetTD=document.all[targetSID];
oDrag.table=event.srcElement.parentElement.parentElement.parentElement;
oDrag.tableW=table.clientWidth;
oDrag.x1=event.x
}else{
oDrag.obj=null;
return false
}
}
function mMove(){
if(!oDrag.obj)return false;
try{
if(window.event.x>=(MainBG.offsetLeft+MainBG.clientWidth))return false;
oDrag.x2=event.x;
var dW=oDrag.x2-oDrag.x1;
oDrag.targetTD.style.width=oDrag.targetTD.clientWidth+dW
oDrag.table.style.width=dW+oDrag.tableW;//------------>!!!
}
catch(x){}
}
function mUp(){
document.body.style.cursor="default";
oDrag.obj=null;
}
function refresh(){
table=TableBG.children[0]
TableBG.style.width=table.clientWidth;
TableBG.style.height=table.clientHeight;
MainBG.style.width=(TableBG.clientHright>=500)?500:TableBG.clientWidth;
MainBG.style.height=(TableBG.clientHright>=500)?500:TableBG.clientHeight+16;//默认,高度超过500px使用滚动
}
function dragInit(){
oDrag=new TDrag();
document.onmousedown = mDown
document.onmousemove = mMove
document.onmouseup = mUp;
}
//-->
</SCRIPT>
</HEAD><BODY onload="dragInit()"><SCRIPT LANGUAGE="JavaScript">
<!--
ot=new TTable();
ot.addData('name','email','phoneCode','address','homepage','oicq')
ot.addData('llrock','[email protected]','123456789','Beijing','user1.7host.com/ccrock','1234567')
ot.addData(1,2,3,4)
ot.addData(1,2,'',4,5,6)
ot.addData(1,2,3,4,5)
//ot.data=[[1,2,3,4],2,3]
ot.trimData()
ot.create()
ot.display()
ot.refresh()
//-->
</SCRIPT>
</BODY>
</HTML>
a=[['name','email'],[1],[1,2,3]]然后直接复给ot.data=a就可以了,或者一行一行的来,把显示数据的任务交给客户端,我想你说的使用数据方便是通过服务器端如
<%
...%>
<table ...>
<tr>
<td>name</td><td>email</td><td>home</td>
</tr> <% for i=1 to 10 %>
<tr>
<td><%rs("name")%></td>
<td><%rs("email")%></td>
<td><%rs("home")%></td>
</tr>
<% rs.movenext
next%>
但愿没有写错,我觉得这样写不是很好,祝你好运
我接触js不过几个月,我们是同辈,呵呵,我一直都用editplus编辑代码,非常灵活,最开始用dw,后来发现她很笨拙,就从机器删掉了,editplus一级棒!
<style>
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
table-layout: fixed;
}.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
}
</style>
<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">
<TR>
<TD width="100" class="tabletitleTD" >标题1</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="100" class="tabletitleTD" >标题2</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" class="tabletitleTD" >标题3</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="50" class="tabletitleTD" >标题4</TD>
<TD width="1" rowspan="4" class="tdwbar" ></TD>
<TD width="200" bgcolor="#0099FF" class="tabletitleTD" >rerewr</TD>
<!-- <td width="150" height="9" align="center" class="tabletitleTD" >职级</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" >描述</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d3 >人头总数</td>
<td width="1" rowspan="2" class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d4>合共工资</td>
<td width="1" rowspan="2"class="tdwbar" ><img src="Image_C/bg01.gif" width="1" height="1"></td>
<td width="150" align="center" class="tabletitleTD" id=d5>涨幅 %</td>-->
</TR>
<TR>
<TD class="tt">123</TD>
<TD width="100" class="tt">123</TD>
<TD width="200" class="tt" style='word-break:break-all'>3463464reyhdytwru868w568asdfasdhadfhadhf</TD>
<TD width="50" class="tt">66</TD>
<TD width="200" class="tt">88</TD>
</TR>
<TR>
<TD height="20" class="tt">123</TD>
<TD width="100" class="tt">111</TD>
<TD width="200" class="tt">44</TD>
<TD width="50" class="tt">77</TD>
<TD width="200" class="tt">iiii</TD>
</TR>
<TR>
<TD class="tt">46</TD>
<TD width="100" class="tt">5645</TD>
<TD width="200" class="tt">757</TD>
<TD width="50" class="tt">757</TD>
<TD width="200" class="tt">456</TD>
</TR>
</TABLE>
style='word-break:break-all'
table-layout: fixed;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style>
.tabletitle {
font: icon;
color: buttontext;
background: threedhighlight;
border-top:1px solid #000000;
border-right: 1px solid #000000;
border-left-style: solid;
border-bottom-style: none;
border-left-width: 1px;
border-left-color: #000000;
}
.tabletitleTD {
background: #0099FF;
overflow:hidden;
height:15;
border-left:1px solid buttonhighlight;
border-right:1px solid buttonshadow;
border-top:1px solid buttonhighlight;
border-bottom:1px solid buttonshadow;
color: #FFFFFF;
}
.tableAct {
background: #FFFFFF;
font: icon;
color: buttontext;
border-right: 1px solid threedshadow;
}
.tableAct TD{
border-left: 1px solid buttonshadow;
}
.tdwbar{
cursor:w-resize;
background:buttonface;
behavior:url(dragline.htc);
}
.tt {
background-color: #FFFFFF;
border-top: 1px none #666666;
border-right: 1px none #666666;
border-bottom: 1px solid #666666;
border-left: 1px none #666666;
white-space: nowrap;
}
.myscroll{FONT-SIZE: 12px;SCROLLBAR-HIGHLIGHT-COLOR: #FFFFFF;SCROLLBAR-SHADOW-COLOR: #e1e1e1;SCROLLBAR-3DLIGHT-COLOR: #e1e1e1;SCROLLBAR-TRACK-COLOR: white; SCROLLBAR-DARKSHADOW-COLOR: white; scrollbar-Base-Color: white; scrollbar-arrow-Color:}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function TTable(name){
this.name=name;
this.cols=new Array();
this.rows=new Array();
this.items=new Array();
this.colcount=0;//实际是列输减一
this.rowcount=0;
this.data=new Array();
//style
this.width=100;//colum width
this.bgc="#e7e7e7";
this.fontfamily="tahoma,arial,helvetica";
//method
this.addData=addData;
this.trimData=trimData;
this.create=create;
this.display=display;
this.refresh=refresh;
}
function TItem(owner,name,data,rindex,cindex,width,bgc,ftc){
this.owner=owner;
this.name=name;
this.data=data;
this.rindex=rindex;
this.cindex=cindex;
this.width=width||owner.width;
this.bgc=bgc||owner.bgc;
this.htmlcode=!rindex?'\n<TD width="100" class="tabletitleTD" >'+data+'</TD>\n<TD width="2" rowspan="'+owner.colcount+'" class="tdwbar" ></TD>':'\n<TD class="tt">'+data+'</TD>';
}function addData(){
var arg=addData.arguments;
var len=arg.length;
this.colcount=Math.max(this.colcount,len);
var tmpdata=new Array();
for(i=0;i<this.colcount;i++){
tmpdata[i]=!arg[i]?'':arg[i];
}
this.data[this.data.length]=tmpdata;
}
function trimData(){
for(i=0;i<this.data.length;i++){
for(j=0;j<this.colcount;j++){
this.data[i][j]=!this.data[i][j]?' ':this.data[i][j];
}
}
}
function create(){
for(i=0;i<this.data.length;i++){
this.items[i]=new Array;
for(j=0;j<this.colcount;j++){
this.items[i][j]=new TItem(this,this.data[i][j],this.data[i][j],i,j)
}
}
}
function display(){
this.htmlcode='';
//this.htmlcode+='\n<div id="MainBG" style="position:absolute; left:100px; top:180px; z-index:1; ;border: 1px none #000000;overflow:auto;" class=myscroll>'
this.htmlcode='\n<div id="TableBG" style="position:absolute; left:0px; top:0px; z-index:2; border: 1px none #000000">'
+'\n<TABLE border="0" cellPadding="0" cellSpacing="0" class="tabletitle" id="tb1">'; for(i=0;i<this.data.length;i++){
this.htmlcode+='\n<tr>';
for(j=0;j<this.colcount;j++){
this.htmlcode+=this.items[i][j].htmlcode;
}
this.htmlcode+='\n</tr>';
}
this.htmlcode+='</table></div>'//+'</div>';
document.write(this.htmlcode)
}
/******************* drag function ************************/
function TDrag(){
this.x1=null;
this.x2=null;
this.obj=null;
this.tableW=null;
this.tdW=null;
this.table=null;
this.targetTD=null;
}
function getTdSid(sid){
var targetSID=sid-1;
while(document.all[targetSID].tagName!='TD'){targetSID--}
return targetSID
}
function mDown(){
oDrag.obj=window.event.srcElement;
if(oDrag.obj.tagName=='TD'&&oDrag.obj.rowSpan!=1){
document.body.style.cursor="e-resize";
var targetSID=getTdSid(event.srcElement.sourceIndex);
oDrag.targetTD=document.all[targetSID];
oDrag.table=event.srcElement.parentElement.parentElement.parentElement;
oDrag.tableW=table.clientWidth;
oDrag.x1=event.x
}else{
oDrag.obj=null;
return false
}}
function mMove(){
if(!oDrag.obj)return false;
try{
// if(window.event.x>=(MainBG.offsetLeft+MainBG.clientWidth))return false;
oDrag.x2=event.x;
var dW=oDrag.x2-oDrag.x1;
oDrag.targetTD.style.width=oDrag.targetTD.clientWidth+dW
oDrag.table.style.width=dW+oDrag.tableW;//------------>!!!
}
catch(x){}
}
function mUp(){
document.body.style.cursor="default";
oDrag.obj=null;
}
function refresh(){
table=TableBG.children[0]
TableBG.style.width=table.clientWidth;
TableBG.style.height=table.clientHeight;
// MainBG.style.width=(TableBG.clientHright>=500)?500:TableBG.clientWidth;
// MainBG.style.height=(TableBG.clientHright>=500)?500:TableBG.clientHeight+16;//默认,高度超过500px使用滚动
}
function dragInit(){
oDrag=new TDrag();
document.onmousedown = mDown
document.onmousemove = mMove
document.onmouseup = mUp;
}
//-->
</SCRIPT>
</HEAD><BODY onload="dragInit()"><SCRIPT LANGUAGE="JavaScript">
<!--
ot=new TTable();
ot.addData('name','email','phoneCode','address','homepage','oicq')
ot.addData('llrock','[email protected]','123456789','Beijing','user1.7host.com/ccrock','1234567')
ot.addData(1,2,3,4)
ot.addData(1,2,'',4,5,6)
ot.addData(1,2,3,4,5)
//ot.data=[[1,2,3,4],2,3]
ot.trimData()
ot.create()
ot.display()
ot.refresh()
//-->
</SCRIPT>
</BODY>
</HTML>