取得控件绝对位置

< HTML >
    
< HEAD >
        
< title > WebForm5 </ title >
        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
        
< script  language ="javascript" >  
        
function getIE(e)
        

            
var top=e.offsetTop; 
            
var left=e.offsetLeft; 
            
var width=e.offsetWidth;
            
var height=e.offsetHeight;
            
while(e=e.offsetParent)
            

                top
+=e.offsetTop; 
                left
+=e.offsetLeft; 
            }
 
            
var m= parseInt(left,10)+parseInt(width,10)+2;//2是误差
            alert("top="+top+"\nleft="+left+"\nWidth="+width+"\nHeight="+height); 
            
//var url ="WebForm7.aspx";
            //window.open(url,'meng', 'height=300, width=400, top='+ (screen.availHeight-300)/2 +', left='+ m +', toolbar=no, menubar=no,scrollbars=no,location=no, status=no')
        }

        
</ script >
    
</ HEAD >
    
< body  MS_POSITIONING ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< INPUT  style ="Z-INDEX: 101; LEFT: 328px; POSITION: absolute; TOP: 160px"  type ="button"
                value
="点我一下"  onclick ="getIE(this);" >
        
</ form >
    
</ body >
</ HTML >

你可能感兴趣的:(控件)