木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2009-07-20 👁 4456 👍 0 💬 0 🔄 来源:本站原创
<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)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 再说Js构造函数 下一篇 → IE6.0下广告代码离奇消失之谜