jjery在ajax被调用两次后发生变化

时间:2017-02-13 16:10:45

标签: javascript jquery

我得到的jquery在每次ajax完成后被解雇

这是一个控制台视图

enter image description here

education-script第23-45行

$(document).ajaxComplete(function(){
    $('.start-date').datepicker();
    $('.end-date').datepicker();

    $('.selectpicker').selectpicker({ });

    $('.education-level').off();

    $('body').on('change', '.education-level', (function() {
        var value = $(this).val();
        console.log(value);

        if (value == 'other') {
            $('.education-other').removeClass('hidden');
            $('.education-level-error').addClass('hidden');
        } else if(value == '') {
            $('.education-level-error').removeClass('hidden');
        } else {
            $('.education-other').addClass('hidden');
            $('.education-level-error').addClass('hidden');
        }
    }));
})

它记录了两次,尝试解除绑定更改但没有成功。 另一个电话是education-script 52-65

$('.education-level').change(function() {
    var value = $(this).val();
    console.log(value);

    if (value == 'other') {
        $('.education-other').removeClass('hidden');
        $('.education-level-error').addClass('hidden');
    } else if(value == '') {
        $('.education-level-error').removeClass('hidden');
    } else {
        $('.education-other').addClass('hidden');
        $('.education-level-error').addClass('hidden');
    }
});

和选择html

    <select class="selectpicker education-level" title="Choose one of the following...">
        <option></option>
        <option>University</option>
        <option>College</option>
        <option>High school</option>
        <option value="other">Other</option>
    </select>

更新

我做了this父级的控制台日志,当检测到更改时,响应解释了问题,selectpicker创建了一个友好的选择框作为原始副本,并且更改正在调用它们但实际上只有一个正在使用中。

enter image description here

0 个答案:

没有答案