Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在引导中触发模式隐藏时,是否可以停止模式隐藏?_Javascript_Jquery_Bootstrap 4 - Fatal编程技术网

Javascript 在引导中触发模式隐藏时,是否可以停止模式隐藏?

Javascript 在引导中触发模式隐藏时,是否可以停止模式隐藏?,javascript,jquery,bootstrap-4,Javascript,Jquery,Bootstrap 4,在引导中,当按下关闭按钮或背景时,是否可以停止模式隐藏 $(document).on('hide.bs.modal', '#test-modal', function(e) { var confirm = confirm("Sure you wanna close this modal?"); if (confirm == true) { // i'm sure, continue closing the modal } else { // halt clo

在引导中,当按下关闭按钮或背景时,是否可以停止模式隐藏

$(document).on('hide.bs.modal', '#test-modal', function(e) {

  var confirm = confirm("Sure you wanna close this modal?");

  if (confirm == true) {

    // i'm sure, continue closing the modal

  } else {

    // halt closing this modal

  } 

});
例如,如果我运行一条语句来检查true或false。如果为false,我可以停止模式隐藏吗

$(document).on('hide.bs.modal', '#test-modal', function(e) {

  var confirm = confirm("Sure you wanna close this modal?");

  if (confirm == true) {

    // i'm sure, continue closing the modal

  } else {

    // halt closing this modal

  } 

});
这里有一把小提琴准备测试


您只需在
hide.bs.modal
中使用
e.preventDefault
即可防止modal关闭。另外,请注意,
confirm
是一个窗口对象,因此您可能应该选择一个不同的变量名来避免这种情况

请参见概念验证示例:

$('testmodel').model('show');
$(document).on('hide.bs.modal','#test modal',函数(e){
var shouldCloseModal=confirm(“确定要关闭此模式吗?”);
如果(!shouldCloseModal){
e、 预防默认值();
} 
});

测试模态
&时代;
试着靠近我然后阻止我!如果你能。。。

是的,如果你有足够的时间,这是可能的。如果一个jquery动画在一段时间内关闭了某个具有某种效果的东西,您可以在它结束之前将其反转或切换动画。谢谢tezza,完美。。。我注意到
confirm
var!好漂亮的!