即使我点击按钮

时间:2016-10-29 06:30:03

标签: javascript jquery twitter-bootstrap

我在成功完成删除操作后面临解雇模式的挑战。

以下是操作模式的屏幕截图:

Confirm Delete modal

当我点击"取消"按钮,模式按预期被解雇,而不像"删除"按钮;即使运作成功。

我可能做错了什么,我该如何解决?

以下是我的代码;

模态对话框:

<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
            </div>

            <div class="modal-body">
                <p>You are about to delete one track, this procedure is irreversible.</p>
                <p>Do you want to proceed?</p>
                <p class="debug-url"></p>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>

触发模态对话框的按钮后面的代码是:

<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#confirm-delete" id="delete" style="display: none;">Delete</button>

然后,我的脚本(处理所有操作):

$('#confirm-delete').on('show.bs.modal', function(e) {
    var rowid = json_array['rowid'];
    $('.btn-ok').click( function() {
        $.ajax({
            url: 'delete_record.php',
            type: "post",
            async: true,
            data: ({ row_id : rowid }),
            success: function(data) {
            }
        });
     });
 );

2 个答案:

答案 0 :(得分:1)

这应该这样做:

$('#confirm-delete').on('show.bs.modal', function(e) {
    var rowid = json_array['rowid'];
    var instance = $(this);
    $('.btn-ok').click( function(){
        instance.modal('hide');                                        
        $.ajax({
            url: 'delete_record.php',
            type: "post",
            async: true,
            data: ({ row_id : rowid }),
            success: function(data) {
            }                                            
        });                                        
     });
 );

答案 1 :(得分:0)

$('#modal').modal('toggle');

更改id / class,这应该有效。如果打开则基本上将其切换为关闭,反之亦然。