像以下这种没有设置明确位置的标签,怎么样获得它的当前位置?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.mydiv{
        position:relative;
        float:left;
overflow:hidden;
background:#0066FF;

</style>
<script type="text/javascript">
function a(){
   var a= document.getElementById("test").getElementsByTagName('div')[0];
   alert(a.style.left);
}
</script>
</head><body>
<div onclick="a();" id="test" class="gg" style='left:0%;top:0%; width:1536px;'>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
    <div style="width:256px; height:256px;" class="mydiv"></div>
</div>
</body>
</html>

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    .mydiv{
            position:relative;
            float:left;
            overflow:hidden;
            background:#0066FF;
            } 
    </style>
    <script type="text/javascript">
    function a(){
       var a= document.getElementById("test").getElementsByTagName('div')[2];
       alert(a.offsetLeft);//这里改了
    }
    </script>
    </head><body>
    <div onclick="a();" id="test" class="gg" style='left:0%;top:0%; width:1536px;'>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
        <div style="width:256px; height:256px;" class="mydiv"></div>
    </div></body>
    </html>