<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Document</title></head><body><div><span id="list1"></span><span id="list2"></span><button onclick="firstWorker()">star</button></div><script type="text/javascript">var w;firstWorker = function() {if(typeof Worker !== "undefined") {w = new Worker("count.js");}w.onmessage = function(event) {document.getElementById("list1").innerHTML = event.data.input;document.getElementById("list2").innerHTML = event.data.result;}}</script></body></html>count.js:///////////////////////////////////////////////////////////////var i = 0;var arr = new Array();arr[0] = 0;arr[1] = 1;function countNum() { i++; postMessage({input:i,result:i+1}); if(i < 10){ setTimeout("countNum()",1000); }}countNum();
添加回答
举报
0/150
提交
取消