好的,我花了一整天阅读问答,但仍然无法完成。我需要创建一个自定义的confirm()函数,其中使用bootstrap模态框来代替默认对话框,如果用户点击“是”,则返回true,如果点击“否”,则返回false。
例如:
<a href="remove.php?id=3" onclick="return custom_confirm('您确定要删除吗?');" />
我的自定义确认函数如下:
function custom_confirm(message) {
// put message into the body of modal
$('#modal-custom-confirmation').on('show.bs.modal', function (event) {
// store current modal reference
var modal = $(this);
// update modal body help text
modal.find('.modal-body #modal-help-text').text(message);
});
// show modal ringer custom confirmation
$('#modal-custom-confirmation').modal('show');
// if Yes button is clicked, return true
// if No button is clicked, return false
// logic here...
}
我的模态框在这里:
<!-- modal: custom confirmation -->
<div class="modal fade text-left" id="modal-custom-confirmation" tabindex="-1" role="dialog" aria-labelledby="modal-help-title">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong class="modal-title" id="modal-help-title">Confirm</strong>
</div><!-- /.modal-header -->
<div class="modal-body">
<p id="modal-help-text"></p>
</div><!-- /.modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-success">Yes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div><!-- /.modal-footer -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->