alert срабатывает раньше
Почему alert срабатывает раньше чем отработает цикл
var myHandler = function () { var Blocks = document.querySelectorAll('.square'); var showAlert = true; var counter = 0; for (var i = 0; i < Blocks.length; i++) { var currentElement = Blocks[i]; if (window.getComputedStyle(currentElement)["backgroundColor"] != "rgb(0, 0, 255)") { if (currentElement.style.display == 'none') { currentElement.style.display = 'block'; showAlert = false; } else { currentElement.style.display = 'none'; }; } else { ++counter; } } if (showAlert) { alert('text ' + counter); } }; var blueButton = document.getElementById("blueButton"); { blueButton.addEventListener("click", myHandler); }; |
Bird17,
Пожалуйста, отформатируйте свой код! Для этого его можно заключить в специальные теги: js/css/html и т.п., например: [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
Цитата:
|
Часовой пояс GMT +3, время: 07:28. |