我的jquery在tab打开之前运行,这就是为什么它无法聚焦我的文本框..帮助我,我能做什么

时间:2017-02-24 10:36:47

标签: jquery html css asp.net bootstrap-modal



** this is my model when i click on model tab 
jquery run before tab open thats why textbox can not focus**
$('.clickfocus').click(function() {
if (this.id == 'Active_pan1') {

    $('#txt_i_ntn').focus();

}
if (this.id == 'Active_pan2') {

    $('#txt_i_Contact').focus();

}
if (this.id == 'Active_pan3') {

    $('#txt_i_orgcode').focus();
}
});

**this is my model **
<div class="modal fade" id="modal_info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 300px !important;margin-top: 105px !important;margin-right: 646px !important;">
        <div class="modal-content">
            <div class="modal-header modal-header-info" style="height: 38px !important;padding-top: 6px !important;padding-bottom: 10px !important;padding-left: 10px !important;padding-right: 10px !important;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h5 id="title_SearchDetails"><i class="glyphicon glyphicon-thumbs-up">Customer Search</i></h5>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="portlet-body" style="padding-right: 8px !important; padding-left: 8px !important;">
                        <div class="tabbable-custom nav-justified">
                            <ul class="nav nav-tabs nav-justified" style="padding-right: 0px !important; padding-left: 5px !important; ">
                                <li id="Active_pan1" class="active clickfocus" style="padding: 0px !important; margin: 0px !important;">
                                    <a id="a_cnic" href="#tab_6_1" data-toggle="tab">#CNIC  </a>
                                </li>
                                <li id="Active_pan2" class="clickfocus" style="padding: 0px !important; margin: 0px !important; ">
                                    <a id="a_name" href="#tab_6_2" data-toggle="tab"> Mobile </a>
                                </li>
                                <li id="Active_pan3" class="clickfocus" style="padding: 0px !important; margin: 0px !important; ">
                                    <a id="a_code" href="#tab_6_3" data-toggle="tab"> Code </a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab_6_1">
                                    <p style="margin-top: 0px;">
                                        <input id="txt_i_ntn" name="txt_i_ntn_name" class="postdata cnickeycodecheck enter_click" type="text" autofocus="autofocus" maxlength="13" placeholder="XXXXXXXXXXXXX" style="text-align: left;width: 38% !important;" checked="checked" />
                                    </p>
                                </div>
                                <div class="tab-pane" id="tab_6_2">
                                    <p style="margin-top: 0px; margin-left: 91px;">
                                        <input id="txt_i_Contact" name="txt_i_Contact_name" class="postdata cnickeycodecheck enter_click" type="text" autofocus="autofocus" maxlength="11" placeholder="XXXXXXXXXXX" style="text-align: left;width: 55% !important;" />
                                    </p>
                                </div>
                                <div class="tab-pane" id="tab_6_3">
                                    <p style="margin-top: 0px; margin-left: 184px;">
                                        <input id="txt_i_orgcode" name="txt_i_orgcode_name" class="postdata cnickeycodecheck enter_click" type="text" autofocus="autofocus" maxlength="7" placeholder="XXXXXXX" style="text-align: left;width: 100% !important;" />
                                    </p>
                                </div>
                            </div>
                        </div>

                    </div>


                </div>
            </div>

            <div class="modal-footer" style="padding-bottom: 6px !important;padding-top: 6px !important;height: 38px !important;padding-left: 10px !important; padding-right: 10px !important;">
                <button type="button" class="btn btn-danger btn-xs red pull-right" data-dismiss="modal" style="margin-left: 3px;">
                    Close
                </button>
                <button id="btn_modal_org" value="org" type="button" class="btn red btn-xs  pull-right btn_modal_class hiddenRow btncustmodal">
                    Search
                </button>
                <button id="btn_modal_cust" value="cust" type="button" class="btn red btn-xs  pull-right btn_modal_class  btncustmodal">
                    Search
                </button>
                @*<button id="btn_modal_g1" type="button" class="btn btn-info btn-xs  pull-right btn_modal_class">
                        Search
                    </button>
                    <button id="btn_modal_g2" type="button" class="btn btn-info btn-xs  pull-right btn_modal_class">
                        Search
                    </button>*@
            </div>
        </div>
    </div><!-- /.modal-content -->
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以使用制表符事件来执行此操作:http://getbootstrap.com/javascript/#tabs-events

   $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        $($(e.target).attr("href")).find('.enter_click').focus();
   })