Как сделать так, чтобы параметр переключения возвращался к значению по умолчанию после закрытия модального события? - PullRequest
0 голосов
/ 15 февраля 2020

Как сделать, чтобы опция переключения возвращалась к значению по умолчанию после закрытия модального события? Я пытаюсь использовать prop checked, но он не работает.

Пробовал ниже, но не работает.

  1. $ ('# on'). Prop ('флажок') ;
  2. $ ('# on'). Prop ('флажок', false);
  3. $ ('# off'). Prop ('флажок', true);

HTML

<div class="modal fade" id="view_modal">
    <div class="modal-body">
        <div class="switch_toggle">
            <input type="radio" id="off" name="status" value="inactive" checked>
            <label for="off" class="text-center">OFF</label>
            <input type="radio" id="on" name="status" value="active">
            <label for="on" class="right text-center">ON</label>
            <span aria-hidden="true"></span>
        </div>  
    </div>
</div>

JS

$('.switch_toggle label').on('click', function(){
    var indicator = $(this).parent('.switch_toggle').find('span');
    if ($(this).hasClass('right')){
        $(indicator).addClass('right');
        console.log("active")   //this is appear
    } else {
        $(indicator).removeClass('right');
        console.log("inactive")    //this is appear
    }
});

$("#view_modal").on('hidden.bs.modal', function(e) {
    $('#on').prop('checked', false);    //this is not working
    console.log("inactive modal 2")    //this is appear
});
...