<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) + "[color=Red]px[/color]";
obj.style.left = Math.round(Math.random()*600) + "[color=Red]px[/color]";
}
</script>
<input type="button" value="move" onclick="Move(document.getElementById('div1'));" />
评论(0)
暂无评论。