在我的当前项目中,我使用了bootbox来替换我的旧的普通提示框和确认框,变得更加时尚。但问题是,在关闭或取消bootbox后,焦点没有返回到我的输入框。
bootbox.alert("Please create a milestone");
$('input[name="mile_stone[]"]:first').focus();
return false;
除了焦点功能外,一切都按预期工作。有没有办法解决这个问题?
在我的当前项目中,我使用了bootbox来替换我的旧的普通提示框和确认框,变得更加时尚。但问题是,在关闭或取消bootbox后,焦点没有返回到我的输入框。
bootbox.alert("Please create a milestone");
$('input[name="mile_stone[]"]:first').focus();
return false;
除了焦点功能外,一切都按预期工作。有没有办法解决这个问题?
请参考这个问题:如何绑定一个函数到Twitter Bootstrap模态框的关闭事件?
对于bootbox模态框,您可以添加以下内容:
$('.bootbox').on('hidden.bs.modal', function() {
$('input[name="mile_stone[]"]:first').focus();
});
<script>
$(function(){
$('#btnAlerta').on('click',function(){
falert('modal title','message you want to view','#nome');
});
});
function falert(tit,msg,obj){
var box = bootbox.alert({
size: 'small',
title: tit,
message:'<p>'+msg+'</p>'
});
box.on('hidden.bs.modal',function(){
$(obj).focus();
});
}
</script>
<input type="text" id="nome" name="nome" />
<button type="button" id="btnAlerta">Alert</button>