Javascript教程_如何取得style中top的值源码教程
top=osmall.offsetTop
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
#big{ position:relative;width:500px; height:400px;border:1px solid #999999;}
#big #small{position:absolute;top:50px; left:80px; width:100px; height:100px; background:#ff0000;}
</style>
<script language="javascript">
function top(){
osmall=document.getElementById("small");
top=osmall.offsetTop;
alert(top);
}
</script>
</head>
<body>
<div id="big" onmouseover="top()">
<div id="small"></div>
</div>
</body>
</html>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
#big{ position:relative;width:500px; height:400px;border:1px solid #999999;}
#big #small{position:absolute;top:50px; left:80px; width:100px; height:100px; background:#ff0000;}
</style>
<script language="javascript">
function top(){
osmall=document.getElementById("small");
if (osmall.currentStyle){top=osmall.currentStyle.top;}//*ie
else if (window.getComputedStyle) { top=osmall.getComputedStyle.top;} //*ff
alert(top);
}
</script>
</head>
<body>
<div id="big" onmouseover="top()">
<div id="small"></div>
</div>
</body>
</html>