【问题标题】:Bootbox alert focus not returning to the inputBootbox 警报焦点未返回到输入
【发布时间】:2014-08-05 07:27:34
【问题描述】:

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

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

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

【问题讨论】:

  • 您能否提供JS Fiddle 代码,用于到目前为止所做的任何工作。

标签: jquery bootbox


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    这个例子是针对 bootbox 警报的,对于其他人(确认等...)只需修改代码即可:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多