为了账号安全,请及时绑定邮箱和手机立即绑定

javascript中return true的作用?

javascript中return true的作用?

夜尽天明ht 2016-05-21 10:15:04
<!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的作用,谢谢
查看完整描述

1 回答

?
夜尽天明ht

TA贡献3条经验 获得超2个赞

大致明白了一点,就是不知道这个return true的作用范围是怎么规定的?

查看完整回答
反对 回复 2016-05-21
  • 1 回答
  • 0 关注
  • 1933 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信