我正在尝试使用 bootbox.js 给出一个模式确认框。这是 fiddle ..
我的代码看起来像这样,但问题是 native javascript 确认掩盖了我使用 bootbox 的自定义确认框。插件:
$(window).bind('beforeunload', function(){
var conf = "All unsaved changes will be lost, are you sure you want to leave the page?";
return bootbox.confirm(conf, function(result)
{
return result;
});
});
任何人都可以告诉我出了什么问题或帮助我了解出了什么问题..?
提前致谢
最佳答案
在本例中使用 jQuery。为了方便起见,我在 anchor 标记中添加了一个“确认”类。您可以使用
阻止默认行为e.preventDefault
然后在 Bootstrap 箱回调中执行其他过程,并在用户提供响应后进行导航。
$('a.confirmation').click(function(e){
e.preventDefault();
var $link = $(this);
bootbox.confirm({
message: "Are you sure you want to continue?",
callback: function (result) {
if(result){ window.location.href = $link.attr('href'); }
}
});
});
关于javascript - 使用 Facebook 等模式确认离开页面的导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21580215/