JS改变表格的列宽

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function a()
        
{
            e
=event.srcElement
            
if(e.tagName=="TABLE"return
                    
while(e.tagName!="TR")
                    e
=e.parentElement
                    
if(e.rowIndex==document.getElementById("datagrid1").rows.length-1return
                    document.getElementById(
"datagrid1").rows[e.rowIndex+1].style.display=(document.getElementById("datagrid1").rows[e.rowIndex+1].style.display=='none')?'':'none'
        }

    
                 
//鼠标拉动列宽
                 function SyDG_moveOnTd(td)
                        
{
                            
if(event.offsetX>td.offsetWidth-10)
                                td.style.cursor
='w-resize';
                            
else
                                td.style.cursor
='default';
                            
if(td.mouseDown!=null && td.mouseDown==true)
                            
{
                                
if(td.oldWidth+(event.x-td.oldX)>0)
                                    td.width
=td.oldWidth+(event.x-td.oldX);
                                td.style.width
=td.width;
                                td.style.cursor
='w-resize';
                                
                                table
=td;
                                
while(table.tagName!='TABLE') table=table.parentElement;
                                table.width
=td.tableWidth+(td.offsetWidth-td.oldWidth);
                                table.style.width
=table.width;
                            }

                        }

                        
function SyDG_downOnTd(td)
                        
{
                            
if(event.offsetX>td.offsetWidth-10)
                            
{
                                td.mouseDown
=true;
                                td.oldX
=event.x;
                                td.oldWidth
=td.offsetWidth;
                                table
=td;while(table.tagName!='TABLE')table=table.parentElement;
                                td.tableWidth
=table.offsetWidth;
                            }

                        }


        
</script>
</HEAD>

<BODY>
<TABLE id="element" style="FONT-SIZE: 9pt; BORDER-COLLAPSE: separate" cellSpacing="0" borderColorDark="#ffffff"
            cellPadding
="2" width="100%" borderColorLight="#888888" border="1" BorderStyle="None">
            
<TBODY>
                
<TR align="center" bgColor="#dcdcdc">
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        style
="BORDER-RIGHT-COLOR: activeborder" onmouseout="this.mouseDown=false">用户编号</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)" onmouseout="this.mouseDown=false">试用时间</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">转正时间</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">性别</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">姓名拼音</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">生日时间</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">民族</TD>
                    
<TD onmouseup="this.mouseDown=false" onmousemove="SyDG_moveOnTd(this)" onmousedown="SyDG_downOnTd(this)"
                        onmouseout
="this.mouseDown=false">身高</TD>
                
</TR>
                
<TR>
                    
<TD style="WIDTH: 75px">2000001</TD>
                    
<TD>1997-3-13 0:00:00</TD>
                    
<TD>1997-3-13 0:00:00</TD>
                    
<TD>1</TD>
                    
<TD>WZJ</TD>
                    
<TD>1965-3-13 0:00:00</TD>
                    
<TD></TD>
                    
<TD>171</TD>
                
</TR>
                
<TR>
                    
<TD style="WIDTH: 75px">2000045</TD>
                    
<TD>2001-2-15 0:00:00</TD>
                    
<TD>2001-3-15 0:00:00</TD>
                    
<TD>0</TD>
                    
<TD>WY</TD>
                    
<TD>1978-8-5 0:00:00</TD>
                    
<TD></TD>
                    
<TD>162</TD>
                
</TR>
                
<TR>
                    
<TD style="WIDTH: 75px">2000046</TD>
                    
<TD>2001-2-23 0:00:00</TD>
                    
<TD>2001-3-23 0:00:00</TD>
                    
<TD>0</TD>
                    
<TD>LQ</TD>
                    
<TD>2001-2-23 0:00:00</TD>
                    
<TD></TD>
                    
<TD>171</TD>
                
</TR>
            
</TBODY>
        
</TABLE>
</BODY>
</HTML>
posted @ 2005-12-28 14:28  横渡  阅读(3855)  评论(3)    收藏  举报