现在的位置: 首页 > 综合 > 正文

html的对象可以通过getBoundingClientRect()取得其真实位置,例子如下:

2013年04月29日 ⁄ 综合 ⁄ 共 1244字 ⁄ 字号 评论关闭

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<table width="200" border="1">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="362" border="1">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="135">&nbsp;</td>
        <td>&nbsp;</td>
        <td><table width="200" border="1" cellpadding="0" cellspacing="0" bordercolor="#0000FF" id="aa" style="border-collapse:collapse;">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<script language="javascript">
 //alert(aa.getBoundingClientRect()["right"]);
 alert(aa.getBoundingClientRect().right);
 for (var i in aa.getBoundingClientRect()){
  document.writeln(i+"="+aa.getBoundingClientRect()[i]);
 }
</script>
</body>
</html>

本文来自:http://blog.csdn.net/sungcong/archive/2005/12/09/547848.aspx

抱歉!评论已关闭.