<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><script>function addLoadEvent(func){ var oldonload=window.onload; if (typeof window.onload !='function'){ window.onload=func; } else{ window.onload=function(){ oldonload(); func(); } } }function positionMessage(){ if(!document.getElementById) return false; if(!document.getElementById) return false; var elem=document.getElementById("message"); elem.style.position="absolute"; elem.style.left="50px"; elem.style.top="100px"; }function moveMessage(){ if(!document.getElementById) return false; if(!document.getElementById("message"))return false; var elem=document.getElementById("message"); var xpos=parseInt(elem.style.left); var ypos=parseInt(elem.style.top); if(xpos==200&&ypos==100){ return true; } if(xpos<200){ xpos++; } if(xpos>200){ xpos--; } if(ypos<100){ ypos++; } if(ypos>100){ ypos--; } elem.style.left=xpos+"px"; elem.style.top=ypos+"px"; movement=setTimeout("moveMessage()",10); }addLoadEvent(positionMessage);addLoadEvent(moveMessage);</script><body><p id="message">whee</p></body></html>这个里面用return true;是不是实现了一个循环,这个地方 if(xpos<200){
xpos++;
}
if(xpos>200){
xpos--;
}
if(ypos<100){
ypos++;
}
if(ypos>100){
ypos--;
}
elem.style.left=xpos+"px";
elem.style.top=ypos+"px";
movement=setTimeout("moveMessage()",10);是不是都在循环,怎么有循环的作用,求告诉return的作用,谢谢
添加回答
举报
0/150
提交
取消