标签:节点 har .post class inpu 机制 ann 操作dom rmi
https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers
if (window.Worker) { ... }
var myWorker = new Worker('worker.js');
// 主线程中
// 发送
first.onchange = function() { // first是一个input元素
myWorker.postMessage([first.value]);
console.log('Message posted to worker');
}
// 接收
myWorker.onmessage = function(e) {
result.textContent = e.data; // result是个p元素
console.log('Message received from worker');
}
// worker.js 中
// 接收和发送
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] * 10);
console.log('Posting message back to main script');
postMessage(workerResult);
}
// 主线程中
myWorker.terminate();
close();
标签:节点 har .post class inpu 机制 ann 操作dom rmi
原文地址:https://www.cnblogs.com/qq3279338858/p/10861552.html