How to make toggle option return to default after Modal event close happen?

十年热恋 提交于 2021-02-08 11:33:48

问题


How to make toggle option return to default after Modal event close happen? I am trying by using prop checked but it is not working.

Tried below, but not working.

  1. $('#on').prop('checked');
  2. $('#on').prop('checked', false);
  3. $('#off').prop('checked', 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
});

来源:https://stackoverflow.com/questions/60236178/how-to-make-toggle-option-return-to-default-after-modal-event-close-happen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!