代码编辑器:
x
1
2
<meta charset="utf-8">
3
<p>计数: <output id="result"></output></p>
4
<button onclick="startWorker()">开始工作</button>
5
<button onclick="stopWorker()">停止工作</button>
6
<p><strong>注意:</strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 Web Workers</p>
7
<script>
8
var w;
9
function startWorker()
10
{
11
if(typeof(Worker)!=="undefined")
12
{
13
if(typeof(w)=="undefined")
14
{
15
w=new Worker("/static/media/html/demo_workers.js");
16
}
17
18
w.onmessage = function(event){