如何将引导程序模态设置为确认窗口,我正在尝试这段代码,但是当模态打开时,它会返回true。
此代码不起作用,允许重定向。在显示模态之前。
引导程序模式:
<a href="https/www.google.com" id="btn-confirm">Confirm</a>
<div id="deletemodel" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<p>Do you really want to delete these record? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info deleteCancel">Cancel</button>
<button type="button" class="btn btn-danger deleteConfirm">Delete</button>
</div>
</div>
</div>
脚本
<script>
var modalConfirm = function(callback){
$("#btn-confirm").on("click", function(){
$("#deletemodel").modal('show');
});
$("#deletemodel .deleteConfirm").on("click", function(){
callback(true);
$("#deletemodel").modal('hide');
});
$("#deletemodel .deleteCancel").on("click", function(){
callback(false);
$("#deletemodel").modal('hide');
});
};
modalConfirm(function(confirm){
if(confirm){
return true;
}else{
return false;
}
});
</script>
有人可以帮助我解决这个问题吗?
答案 0 :(得分:0)
只需在JS中更改几行:
$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});
e
是单击事件。
preventDefault
告诉浏览器不要遵循HTML默认行为(通常以JS行为为准)。
$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});