3

在我当前的项目中,我使用 bootbox 替换了我旧的普通警报和确认框到一个时尚的。但问题是在关闭或关闭 bootbox 后,它的焦点没有返回到我的输入。

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

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

4

2 回答 2

5

看到这个问题:Bind a function to Twitter Bootstrap Modal Close

在 bootbox modal 的情况下,您可以添加以下内容:

$('.bootbox').on('hidden.bs.modal', function() { 
    $('input[name="mile_stone[]"]:first').focus();
});
于 2014-08-05T13:38:02.763 回答
3

创建一个通用函数来聚焦而不重复代码。

此示例用于引导箱警报,其他人(确认等...)只需修改代码:

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

于 2019-01-30T13:46:57.043 回答