FF下无法移动元素解决方法

<div id="div1" style="width:120px; height:120px; position:absolute; background-color:#000000"></div>
<br/><br/><br/><br/><br/><br/><br/><br/>
<script type="text/javascript">
//随机移动
function Move(obj)
{
    obj.style.top = Math.round(Math.random()*600);
    obj.style.left = Math.round(Math.random()*600);
}
</script>
<input type="button" value="move" onclick="Move(document.getElementById('div1'));" />

上边代码在IE下能正常运行,但在FF(2.0)下div却无法移动,Google了下,原来在FF下移动元素的位置时,必须带个单位:

<div id="div1" style="width:120px; height:120px; position:absolute; background-color:#000000"></div>
<br/><br/><br/><br/><br/><br/><br/><br/>
<script type="text/javascript">
//随机移动
function Move(obj)
{
    obj.style.top = Math.round(Math.random()*600) + "px";
    obj.style.left = Math.round(Math.random()*600) + "px";
}
</script>
<input type="button" value="move" onclick="Move(document.getElementById('div1'));" />


上一篇: 再说Js构造函数
下一篇: IE6.0下广告代码离奇消失之谜
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 0 | 引用: 0 | 查看次数: 3809
发表评论
登录后再发表评论!