日期:2014-05-18 浏览次数:20480 次
function funTouch(){ var a = 10; var b = 20; var c = 10; alert(a = b);//执行a=b后输出a的值~也就是20 alert(a == b); //输出true alert(a == c); //输出false }
------解决方案--------------------
呵呵
------解决方案--------------------
第二题
最快16秒
最慢33秒~把相遇会掉头的蚂蚁看作穿行而过就行了,实际是一样的。
------解决方案--------------------
<!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> <title>蚂蚁爬行演示</title> <style type="text/css"> td{ border:1px solid black; } </style> </head> <body> <script type="text/javascript"> function Bamboo(length,row){ Bamboo.instance=this; this.ants=[]; this.length=length; this.row=row; for(var i=0;i<=length;i++){ var td=document.createElement("td"); row.appendChild(td); } this.start=function(){ setInterval("Bamboo.instance._doWalk()",1000); } this._doWalk=function(){ for(var i=0,j=this.ants.length;i<j;i++){ if(!this.ants[i].stop)this.ants[i].walk(); } } } function ant(bamboo,position,direction){ this.bamboo=bamboo; bamboo.ants.push(this); this.position=position; this.direction=direction; this.stop=false; } ant.prototype.walk=function(){ this.bamboo.row.cells[this.position].innerHTML=""; if(this.direction){ this.position++; }else{ this.position--; } if(this.position<0){ this.stop=true; return this.bamboo.row.cells[0].innerHTML=""; } if(this.position>this.bamboo.length){ this.stop=true; return this.bamboo.row.cells[this.position-1].innerHTML=""; } this.bamboo.row.cells[this.position].innerHTML="*"; } window.onload=function(){ var table=document.getElementById("bamboo"); var tr=document.createElement("tr"); table.appendChild(tr); for(var i=0;i<=39;i++){ var td=document.createElement("td"); tr.appendChild(td); td.innerHTML=i; } tr=document.createElement("tr"); table.appendChild(tr); var bamboo=new Bamboo(39,tr); var ant1=new ant(bamboo,9,true); var ant2=new ant(bamboo,15,true); var ant3=new ant(bamboo,23,false); var ant4=new ant(bamboo,33,false); bamboo.start(); } </script> <table><tbody id="bamboo"></tbody></table> </body> </html>
------解决方案--------------------
1题: 20 true false
2题:就不知道了,伤脑筋