主要用到offsetTop,offsetLeft(获取控件坐标)。还有offsetHeight,offsetWidth(屏幕的高和宽)
<%
...
@ Page language="c#" AutoEventWireup="false" Inherits="gr.Test"
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title > 测试 </ 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 getFocus()
...{
var top;
var width;
top = document.all["txt"].offsetTop;
width = document.all["txt"].offsetLeft;
document.all["txtResult"].value = top +","+width;
}
//-->
</ script >
</ HEAD >
< body MS_POSITIONING ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
</ form >
< table width ="100%" height ="100%" >
< tr >
< td height =100 ></ td >
</ tr >
< tr >
< td >< input id =txtResult type =text ></ td >
</ tr >
< tr >
< td >< input id =txt type =text ></ td >
</ tr >
< tr >
< td >< input id =bt type =button onclick ="getFocus()" value =获取 ></ td >
</ tr >
</ table >
</ body >
</ HTML >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title > 测试 </ 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 getFocus()
...{
var top;
var width;
top = document.all["txt"].offsetTop;
width = document.all["txt"].offsetLeft;
document.all["txtResult"].value = top +","+width;
}
//-->
</ script >
</ HEAD >
< body MS_POSITIONING ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
</ form >
< table width ="100%" height ="100%" >
< tr >
< td height =100 ></ td >
</ tr >
< tr >
< td >< input id =txtResult type =text ></ td >
</ tr >
< tr >
< td >< input id =txt type =text ></ td >
</ tr >
< tr >
< td >< input id =bt type =button onclick ="getFocus()" value =获取 ></ td >
</ tr >
</ table >
</ body >
</ HTML >