针对HTML5的Web Worker使用攻略

2019-01-28 16:02:02于丽
  •       var timer = (new Date()).valueOf();          console.log('开始计算:40','时间:'+ timer );   
  •       setTimeout(function(){              console.log('定时器<span style="width: auto; height: auto; float: none;" id="14_nwp"><a style="text-decoration: none;" mpid="14" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=619521ab1ccffd45&k=%BA%AF%CA%FD&k0=%BA%AF%CA%FD&kdi0=0&luki=2&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=45fdcf1cab219561&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F1183%2Ehtml&urlid=0" id="14_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">函数</span></a></span>在计算数列时执行了', '时间:'+ (new Date()).valueOf() );   
  •       },1000);          worker.postMessage(40);   
  •       console.log('我在计算数列的时候执行了', '时间:'+ (new Date()).valueOf() );      }     
  •   </script>   </<span style="width: auto; height: auto; float: none;" id="15_nwp"><a style="text-decoration: none;" mpid="15" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=619521ab1ccffd45&k=head&k0=head&kdi0=0&luki=6&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=45fdcf1cab219561&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F1183%2Ehtml&urlid=0" id="15_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>>  
  • <body>   </body>  
  • </html>  

      在Chrome中打开fibonacci.html,控制台得到如下输出:
     
    开始计算:40 时间:1316508212705
    我在计算数列的时候执行了 时间:1316508212734
    定时器