简体   繁体   English

如何读取引导程序确认OK / Cancel事件?

[英]how to read bootstrap confirmation OK/Cancel event ?

I am developing MVC application. 我正在开发MVC应用程序。 I am using bootstrp for CSS. 我正在为CSS使用bootstrp。

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 您是否尝试过bootboxjs,它通过方式使用Bootstrap

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. 就个人而言,我在每个模式按钮上使用click事件来执行我想要的操作。

I don't think that there is a result sent by the modal, as we can see in other languages. 我不认为模态会发送结果,正如我们在其他语言中所看到的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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