像以下这种没有设置明确位置的标签,怎么样获得它的当前位置?<!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>
解决方案 »
- 判断不起作用return false 会阻止提交
- 正则表达式,从符合匹配的字符串中再匹配一个条件???
- js,this指哪了
- extjs的Store中几个属性方法的功能是什么
- dom 文本对象模型的问题,轻松获取100分。
- 请教这样正则表达式如何写
- 为何将xmlHttp.responseXML.documentElement传进函数后无法用dom解析?
- ckeditor在firefox下的radiobutton、checkbox控件无右键属性菜单
- JAVASCRIPT中有没有类似PL/SQL中的MOD的函数啊?
- 急急,怎样在输入第一个文本框以后,就输出以第一个文本框其他文本框的内容
- 请问这段代码的流程是怎样的??详细讲解一下。
- 这几个坐标值都是什么意思啊?
<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>