像以下这种没有设置明确位置的标签,怎么样获得它的当前位置?<!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>
<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>
解决方案 »
- 问一个关于C++lambda表达式的问题
- 怎么打印网页的一部分
- 问一个关于单选框的问题,急谢谢了。。。。。。。。。。。。。。。。
- JSP不通过form表单接受JavaScript的prompt参数问题
- 一个有点特殊的拖放问题
- 未保存在数据库之前,怎么样数据自动相加并得出结果
- 如何定位n*n表格中所选中的某一单元格
- 大哥.这个function错在哪里????help~``````````
- 用WINDOW .OPEN打开一个小窗口网页,如何控制其在窗口上的位置。。如控制它在右下脚落
- javascript是用什么函数来测试电脑是否已经在网上.
- 请问这段代码的流程是怎样的??详细讲解一下。
- 这几个坐标值都是什么意思啊?
<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>