问题
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.
- $('#on').prop('checked');
- $('#on').prop('checked', false);
- $('#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