W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript Web Workers API</h1> <p>Count numbers: <output id="result"></output></p> <button onclick="startWorker()">开始 Worker</button> <button onclick="stopWorker()">停止 Worker</button> <script> let w; function startWorker() { if(typeof(w) == "undefined") { w = new Worker("/demo/js/workers.js"); } w.onmessage = function(event) { document.getElementById("result").innerHTML = event.data; }; } function stopWorker() { w.terminate(); w = undefined; } </script> </body> </html>