FF不支持position:relative吗?
看下面的代码,改变style.posTop,posLeft属性,可以以p元素上下移动,在IE和opera里面都工作正常,可是在FF里面一定反应都没有,
什么原因,
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GB18030 ">
<title> Insert title here </title>
<style type= "text/css ">
#a{background-color:red;border:1px solid black;position:relative;}
#b{background-color:blue;border:1px solid black;}
</style>
</head>
<body>
<p id= "a "> aaaaaaaaaaaaaaaaa </p> cccc
<p id= "b "> bbbbbbbbbbbbbbbb </p>
<button onclick= "down() "> 下移 </button>
</body>
<script type= "text/javascript ">
function down(){
p = document.getElementById( "a ");
//alert(p.style.position);
//alert(p.style.posTop);
//alert(p.style.posLeft);
p.style.posTop =p.style.posTop + 10;
p.style.posLeft =p.style.posLeft + 20;
}
</script>
</html>
------解决方案--------------------请使用
document.getElementByID( "id ").style.left = "123px ";
document.getElementByID( "id ").style.top = "123px ";
另外,一定要加单位 "122px "
------解决方案--------------------var temp = parseInt(p.style.posTop)+20;
p.style.posTop = temp + "px ";
------解决方案--------------------var temp = parseInt(p.style.top)+20;
p.style.top = temp + "px ";
temp = parseInt(p.style.left)+20;
p.style.left = temp + "px ";