我尝试使用该按钮,同时将值设置为"开始"为了进行创建红色圆圈,我按下按钮,然后切换到"暂停",因此停止创建红色圆圈。
问题是当我按下"开始"按钮浏览器崩溃。
@tutor.each do |tutor|
tutor.profile.fees_to(10)
end
答案 0 :(得分:0)
您需要使用setTimeout或setInterval而不是while循环。 while循环将锁定浏览器,您将无法翻转用于结束循环的位。此外,while循环运行速度非常快,因此您可以在短时间内添加大量元素。使用计时器,您可以控制速率。
function addElem(){
var elemCreate = document.createElement("div");
elemCreate.className = "circle";
document.querySelector(".appWrap").appendChild(elemCreate);
}
var timer;
function changeState(){
if ( actionBtn.value == "Start" ) {
actionBtn.value = "Pause";
timer = window.setInterval(addElem, 500);
}
else {
actionBtn.value = "Start";
window.clearTimeout(timer);
}
}