怎么样在javacript中获取控件坐标?
主要用到offsetTop,offsetLeft(获取控件坐标)。还有offsetHeight,offsetWidth(屏幕的高和宽)
<%@Pagelanguage="c#"AutoEventWireup="false"Inherits="gr.Test"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>测试</title>
<metaname="GENERATOR"Content="MicrosoftVisualStudio.NET7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
<scriptlanguage=javascript>
<!--
functiongetFocus()
{
vartop;
varwidth;
top=document.all["txt"].offsetTop;
width=document.all["txt"].offsetLeft;
document.all["txtResult"].value=top+","+width;
}
//-->
</script>
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
</form>
<tablewidth="100%"height="100%">
<tr>
<tdheight=100></td>
</tr>
<tr>
<td><inputid=txtResulttype=text></td>
</tr>
<tr>
<td><inputid=txttype=text></td>
</tr>
<tr>
<td><inputid=bttype=buttononclick="getFocus()"value=获取></td>
</tr>
</table>
</body>
</HTML>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>测试</title>
<metaname="GENERATOR"Content="MicrosoftVisualStudio.NET7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
<scriptlanguage=javascript>
<!--
functiongetFocus()
{
vartop;
varwidth;
top=document.all["txt"].offsetTop;
width=document.all["txt"].offsetLeft;
document.all["txtResult"].value=top+","+width;
}
//-->
</script>
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
</form>
<tablewidth="100%"height="100%">
<tr>
<tdheight=100></td>
</tr>
<tr>
<td><inputid=txtResulttype=text></td>
</tr>
<tr>
<td><inputid=txttype=text></td>
</tr>
<tr>
<td><inputid=bttype=buttononclick="getFocus()"value=获取></td>
</tr>
</table>
</body>
</HTML>
本文地址:http://www.45fan.com/dnjc/70712.html