PHP: Show yes/no confirmation dialog

后端 未结 13 2081
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 18:27

My PHP page has a link to delete one MySQL table datum. I want it to be in such a way that when I click the \'delete\' link a confirmation box should appear and it should ask \

相关标签:
13条回答
  • 2021-01-30 19:10

    The best way that I found is here.

    HTML CODE

    <a href="delete.cfm" onclick="return confirm('Are you sure you want to delete?');">Delete</a>
    

    ADD THIS TO HEAD SECTION

    $(document).ready(function() {
        $('a[data-confirm]').click(function(ev) {
            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><h3 id="dataConfirmLabel">Please Confirm</h3></div><div class="modal-body"></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;
        });
    });
    

    You should add Jquery and Bootstrap for this to work.

    0 讨论(0)
提交回复
热议问题