简体   繁体   English

Bootstrap模态对话框需要单击两次才能在文本框中获得焦点

[英]Bootstrap modal dialog requires two clicks to get focus in textbox

I'm displaying the div below using the Bootstrap modal() method. 我正在使用Bootstrap modal()方法显示下面的div。 When it displays I have to click the textbox (id=txtQueriedByUserFilter) twice to get the cursor to stay in the textbox so I can type a search term. 当它显示时,我必须单击文本框(id = txtQueriedByUserFilter)两次,以使光标停留在文本框中,以便我可以输入搜索词。

How can I get the first click to set the focus? 如何获得第一次单击以设置焦点? I've even tried using jQuery to set the focus and that doesn't work. 我什至尝试使用jQuery设置焦点,但这不起作用。

$('#roster-filter-modal').modal();

    <div class="modal fade hide" id="roster-filter-modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="padding: 0px;">
                    <h3 style="line-height: 20px;background: #333;padding: 10px;color: #fff;font-weight: normal;font-size: 15px;margin-bottom:0px;">
                        Roster Filter Options
                    </h3>
                </div>
                <div class="modal-body">
                    <div class="filter-form module module-open" style="margin-top: 0px; margin-bottom: 20px; margin-right: 0px;  padding: 10px; border: 0px;">
                        <table  style="">
                            <tbody>
                                <tr>
                                    <td style=""></td>
                                    <td style="font-family: 'LatoBold'; width: 18px; ">
                                        Queried By User<br/>
                                        <input type="text" id="txtQueriedByUserFilter"  /> 
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                    </div>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a id="roster-filter-confirm" class="btn btn-primary" >Filter Roster</a>
                </div>
            </div>
        </div>
    </div>

我从顶部div中删除了此属性,从而解决了该问题。

tabindex="-1"

Maybe this can welp: 也许这可以使:

$(function(){
     $('.modal').find('input').first().focus();

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM