日期:2014-05-16  浏览次数:20341 次

晕了~~~
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
var   width=o.offsetWidth--用变量记录
window.status=width--显示
o.style.width=100
}
我想问一下我记录开始该层宽的值width,但为什么后面只要修改了该层的宽就会改变width的值呢,这样的话我该怎么处理呢?谢谢

------解决方案--------------------
测试了下,不会出现这种情况啊,有可能是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 ">
------解决方案--------------------
很明显正因为水火说的你调用了好多次move事件,就是因为你用的onmousemove事件,在鼠标移动过程中就调用了知道n次,不应该写在这个事件里面,写在外面吧~~~