测试了下,不会出现这种情况啊,有可能是move这个函数被多次调用,看看什么地方调用了。
比方说下面的程序,点第二次就会出现楼主说的情况。
并且最好别用关键字<div id="div1">test</div>
<script language=javascript>
function aaa(){
var aaa=document.getElementById("div1").offsetWidth
//alert(aaa)
document.getElementById("div1").style.width="5000"
//document.getElementById("div1").innerHTML="555555555555555555555555"
//alert(aaa)
window.status=aaa
}
</script>
<input type="button" onclick="aaa()" value="test">

解决方案 »

  1.   

    我明白水火的例子,但是麻烦你看一下我的代码
    <script language="javascript">
    window.onload=init;
    function init(){
    div1=document.getElementById("wc1")
    div2=document.getElementById("wc2")
    button1=document.getElementById("show_wc1")
    button2=document.getElementById("show_wc2")
    add(div1,button1)
    add(div2,button2)
    }function add(o,p){
    p.onmousemove=function(){move(o,p)};
    }function move(o,p){
    o.style.display="block"
    o.top=p.offsetTop+p.offsetHeight;
    o.left=p.offsetLeft+Math.ceil(p.offsetWidth/2)-Math.ceil(o.offsetWidth/2);
    o.style.left=o.left
    o.style.top=o.top
    width123=o.offsetWidth------用width记录初始宽
    window.status=width123------显示
    o.style.width=100------修改
    }
    </script>
    到这就出错,我还没加setTimeout,以前没发现,不知道是什么原因呢?脑子大了
      

  2.   

    很明显正因为水火说的你调用了好多次move事件,就是因为你用的onmousemove事件,在鼠标移动过程中就调用了知道n次,不应该写在这个事件里面,写在外面吧~~~