Bootbox警报焦点不返回输入

时间:2014-08-05 07:27:34

标签: jquery bootbox

在我目前的项目中,我使用bootbox替换旧的普通警报并确认时尚盒子。但问题是在关闭或解除引导盒之后,其焦点不会返回到我的输入。

    bootbox.alert("Please create a milestone");
    $('input[name="mile_stone[]"]:first').focus();
    return false;

除焦点功能外,一切都按预期工作。有什么方法可以解决这个问题吗?

2 个答案:

答案 0 :(得分:5)

请参阅此问题:Bind a function to Twitter Bootstrap Modal Close

对于bootbox模式,您可以添加以下内容:

$('.bootbox').on('hidden.bs.modal', function() { 
    $('input[name="mile_stone[]"]:first').focus();
});

答案 1 :(得分:0)

创建一个通用函数来集中精力而不重复代码。

此示例用于启动箱警报,对于其他警报(确认等),只需修改代码即可:

<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>

遵循实际中的示例 https://jsfiddle.net/marsites/tLwo253e/

相关问题