问题描述
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><HTML><HEAD><TITLE>NewDocument</TITLE><METANAME="Generator"CONTENT="EditPlus"><METANAME="Author"CONTENT=""><METANAME="Keywords"CONTENT=""><METANAME="Description"CONTENT=""><scripttype="text/javascript">functionGrid(){varself=this;this.init=function(){vartableHeader=newArray;tableHeader[tableHeader.length]="编号";tableHeader[tableHeader.length]="名称";tableHeader[tableHeader.length]="单位";tableHeader[tableHeader.length]="单价";tableHeader[tableHeader.length]="数量";tableHeader[tableHeader.length]="金额";varcolLength=6;varcolWidths=newArray;colWidths[colWidths.length]="100";colWidths[colWidths.length]="150";colWidths[colWidths.length]="80";colWidths[colWidths.length]="80";colWidths[colWidths.length]="80";colWidths[colWidths.length]="120";//创建gridself.divBoxObj=document.getElementById("myTableDiv");self.tableObj=document.createElement("table");self.tableObj.id="wwTable";self.tableObj.style.tableLayout="fixed";self.tableObj.cellPadding=0;self.tableObj.cellSpacing=0;self.tableObj.style.borderCollapse="collapse";self.tableObj.border=1;self.tableObj.borderColor="#cecece";self.tableObj.height="22px";varelRow=self.tableObj.insertRow();for(i=0;i<colLength;i++){varelCell=elRow.insertCell();elCell.align="center";elCell.height="22px";elCell.width=colWidths[i];elCell.onmousemove=self.grid_onMouseMove;elCell.onmousedown=self.grid_onMouseDown;elCell.onmouseup=self.grid_onMouseUp;elCell.innerText=tableHeader[i];}self.tableObj.insertRow().height="22px";self.tableObj.insertRow().height="22px";self.divBoxObj.appendChild(self.tableObj);varhr=document.createElement("<hrid='myHr'style='DISPLAY:none;WIDTH:1px;POSITION:absolute;HEIGHT:132px'color=black>");self.divBoxObj.appendChild(hr);}this.grid_onMouseMove=function(){varEventSource=event.srcElement;//捕获触发事件的对象this.col=EventSource.cellIndex;self.tableObj.rows(0).style.cursor="default";if(this.col>0){if(event.x-parseInt(self.divBoxObj.offsetLeft)>=parseInt(self.tableObj.rows(0).cells(this.col).offsetLeft)-12-self.divBoxObj.scrollLeft&&event.x-parseInt(self.divBoxObj.offsetLeft)<=parseInt(self.tableObj.rows(0).cells(this.col).offsetLeft)+7-self.divBoxObj.scrollLeft){self.tableObj.rows(0).style.cursor="e-resize";if(this.onMouseDownFlag){if(parseInt(this.tdWidth)+parseInt((parseInt(event.x)-parseInt(this.downOffsetLeft)))>0){self.tableObj.rows(0).cells(this.changeCol-1).width=parseInt(this.tdWidth)+parseInt((parseInt(event.x)-parseInt(this.downOffsetLeft)));}elseif(parseInt(this.tdWidth)+parseInt((parseInt(event.x)-parseInt(this.downOffsetLeft)))<=0){self.tableObj.rows(0).cells(this.changeCol-1).width=3;}document.getElementById("myHr").style.left=event.x+parseInt(self.divBoxObj.scrollLeft)-parseInt(self.divBoxObj.offsetLeft)-2;}}else{self.tableObj.rows(0).style.cursor="default"}}}this.grid_onMouseUp=function(){document.getElementById("myHr").style.display="none";this.tableEventSource.releaseCapture();this.onMouseDownFlag=false;this.downOffsetLeft=0;this.tdWidth=0;this.col=-1this.changeCol=-1}this.grid_onMouseDown=function(){this.tableEventSource=event.srcElement;//捕获触发事件的对象if(self.tableObj.rows(0).style.cursor=="e-resize"){document.getElementById("myHr").style.display="block";document.getElementById("myHr").style.height=self.tableObj.rows(0).offsetHeight;document.getElementById("myHr").style.left=event.x+parseInt(self.divBoxObj.scrollLeft)-parseInt(self.divBoxObj.offsetLeft)-2;document.getElementById("myHr").style.top=parseInt(self.tableObj.offsetTop)+2;this.changeCol=this.col;this.downOffsetLeft=event.x;this.tdWidth=self.tableObj.rows(0).cells(this.changeCol-1).width;this.onMouseDownFlag=true;this.tableEventSource.setCapture();}}this.init();}functiontoOnload(){varGird=newGrid();}</script></HEAD><BODYonload="toOnload();">希望高手能在我代码基础上修改正确。<divid="myTableDiv"style="FONT-SIZE:12px;overflow:auto;clip:rect();width:100%;height=64%;border:1px#CECECEsolid;FONT-FAMILY:宋体;"></div></BODY></HTML>
解决方案
解决方案二:
帮顶!
解决方案三:
该回复于2010-01-19 17:24:04被版主删除
解决方案四:
楼主想干嘛说清楚