@jakiro1007

Почему не работает скрипт?

Есть скрипт:
var currentTab = 0; // Current tab is set to be the first tab (0)
    showTab(currentTab); // Display the current tab

    function showTab(n) {
        // This function will display the specified tab of the form ...
        var x = document.getElementsByClassName("test__step");
        x[n].style.display = "block";

        // ... and fix the Previous/Next buttons:
        if (n == (x.length - 1)) {
            document.getElementsByClassName("nextBtn").innerHTML = "Отправить";
        }
        console.log(n)
        // ... and run a function that displays the correct step indicator:
        fixStepIndicator(n)
    }

    function nextPrev(n) {
        // This function will figure out which tab to display
        var x = document.getElementsByClassName("test__step");
        // Exit the function if any field in the current tab is invalid:
        // Hide the current tab:
        x[currentTab].style.display = "none";
        // Increase or decrease the current tab by 1:
        currentTab = currentTab + n;
        // if you have reached the end of the form... :



        // Otherwise, display the correct tab:
        showTab(currentTab);
    }



    function fixStepIndicator(n) {
        // This function removes the "active" class of all steps...
        var i, x = document.getElementsByClassName("step");
        for (i = 0; i < x.length; i++) {
            x[i].className = x[i].className.replace("active", "");
        }
        //... and adds the "active" class to the current step:
        x[n].className += " active";
    }


вот эта часть кода
if (n == (x.length - 1)) {
       document.getElementsByClassName("nextBtn").innerHTML = "Отправить";
}

Должна менять на последнем вопросе у кнопки с классом nextBtn текст на "Отправить", но не меняет, ошибки в консоле тоже нету. В чем может быть проблема?
  • Вопрос задан
  • 107 просмотров
Пригласить эксперта
Ответы на вопрос 2
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
getElementsByClassName возвращает не один элемент, а коллекцию элементов. Ну а у коллекции нет свойства innerHTML.
Ответ написан
Stalker_RED
@Stalker_RED
document.querySelector(".nextBtn").innerHTML = "Отправить";
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы