如果您可以将计算算法转换为可迭代调用的内容,则可以使用具有短超时值的setTimeout来频繁地将控制权释放回浏览器。
例如,像这样的东西
function doCalculation(){ //do your thing for a short time //figure out how complete you are var percent_complete=.... return percent_complete;}function pump(){ var percent_complete=doCalculation(); //maybe update a progress meter here! //carry on pumping? if (percent_complete<100) { setTimeout(pump, 50); }}//start the calculationpump();


