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

Рейтинг: 0Ответов: 1Опубликовано: 08.12.2014

Всем привет.

Есть форма.

<form method="POST" action="<?php echo base_url();?>cabinet/registration" style="font-size: 16px;">

            <input type="text" name="email" id="email" value=""/>

            <input type="password" name="password" id="password" value=""/>

            <input type="password" name="re_password" id="re_password" value=""/>

            <input type="submit" value="Регистрация" name="registration" class="registration_submit" id="registration" disabled />
    </form>

Есть скрипт на Javascript, который проверяет, не пустые ли поля:

function checkParams() {
    var email = $('#email').val();
    var password = $('#password').val();
    var re_password = $('#re_password').val();

    if(email.length != 0 && password.length != 0 && re_password.length != 0) {
        $('#registration').removeAttr('disabled');
    } else {
        $('#registration').attr('disabled', 'disabled');
    }
}

Посмотрите, пожалуйста, почему не удаляется атрибут disabled у кнопки. Хотя в условия входит все нормально!

Ответы

▲ 1

Всё и так у вас прекрасно работает!

function checkParams() {
    var email = $('#email').val();
    var password = $('#password').val();
    var re_password = $('#re_password').val();

    if(email.length != 0 && password.length != 0 && re_password.length != 0) {
        $('#registration').removeAttr('disabled');
    } else {
        $('#registration').attr('disabled', 'disabled');
    }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="POST" action="<?php echo base_url();?>cabinet/registration" style="font-size: 16px;">

            <input type="text" name="email" id="email" value=""/>

            <input type="password" name="password" id="password" value=""/>

            <input type="password" name="re_password" id="re_password" value=""/>

            <input type="submit" value="Регистрация" name="registration" class="registration_submit" id="registration" disabled />
    </form>