Почему скрипт не работает в firefox?
<!DOCTYPE html> <html> <head> <title>3rert</title> </head> <body> <input type="text" id="saveInput" maxlength="10" placeholder="name..."> <input type="button" id="saveButton" value="Cохранить"> <script> document.getElementById("saveInput").focus(); document.getElementById("saveButton").onclick = function () { var input = document.getElementById("saveInput"); var regEx = /[\W]/; if (!input.value || regEx.test(input.value)) { var time = 500, dist = 3, orig = input.style.cssText, start = (new Date()).getTime(); input.style.position = "relative"; input.style.border = "2px solid #f00"; input.style.boxShadow = "0 0 3px 1px #f00"; animate(); function animate() { var now = (new Date()).getTime(), elapsed = now - start, fraction = elapsed / time; if (fraction < 1) { var x = dist * Math.sin(fraction*20*Math.PI); input.style.left = x + "px"; setTimeout(animate, Math.min(25, time-elapsed)); } else { input.style.cssText = orig; input.value = ""; input.focus(); } } } else { alert(true); } }; </script> </body> </html> Во всех браузерах работает анимация, а в firefox нет. почему? Не срабатывает именно функция animate() |
Что-то у меня с firefox
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>3rert</title> </head> <body> <input type="text" id="saveInput" maxlength="10" placeholder="name..."> <input type="button" id="saveButton" value="Cохранить"> <script> document.getElementById("saveButton").onclick = function () { var input = document.getElementById("saveInput"); if (input) { alert("Вхождение в if"); anim(); function anim() { alert("функция anim"); } } }; </script> </body> </html> почему во всех браузерах срабатывают 2 алерта, а в firefox только первый? |
ReferenceError: anim is not defined
Вынесите anim после if() {} |
zebra,
спасибо. Да, это я понял. Не могу найти объяснение почему она не может быть определена. Кстати, первый пример взял из книги Флэнагана |
Часовой пояс GMT +3, время: 06:19. |