简体   繁体   中英

how to read bootstrap confirmation OK/Cancel event ?

I am developing MVC application. I am using bootstrp for CSS.

I am using alert/dialog for confirmation on the delete the record. but was confused about how to read the response of user for OK or cancel.

 var href = $(this).attr('href');
        if (!$('#dataConfirmModal').length) {
            $('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h6 id="dataConfirmLabel">Deactivation Confirmation</h6></div><div class="modal-body">Are you sure to deactive @Model.Name ? </div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button><a class="btn btn-primary" id="dataConfirmOK">OK</a></div></div>');
        } 
        $('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
        $('#dataConfirmOK').attr('href', href);
        $('#dataConfirmModal').modal({show:true});
        return false;

Have you tried bootboxjs it uses Bootstrap by the way

I'll give you a sample code:

bootbox.confirm("Are you sure?", function(result) {
  if (result)
    {
      Example.show("You press Ok");
     }
   else
   {
      Example.show("You press Cancel");
   }
}); 

Personally, i use click event on each modal button to perform the action i want.

I don't think that there is a result sent by the modal, as we can see in other languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM