简体   繁体   English

单击选项卡时,twitter引导程序选项卡设置输入焦点

[英]twitter bootstrap tab set input focus when tab click

I'm using this http://getbootstrap.com/javascript/#tabs to create tabs in my forms. 我正在使用此http://getbootstrap.com/javascript/#tabs在表单中创建标签。
What i need is to set focus on first input="text" that is displayed. 我需要的是将注意力放在显示的第一个input="text"上。

I was unable to find it in documentation or elsewhere. 我在文档或其他地方找不到它。

<div class="tabs">
<ul class="nav nav-tabs">
   <li class="active"><a data-toggle="tab" href="#login1">
      <span class="icon-key"></span>Login</a>
   </li>
   <li class="">
      <a data-toggle="tab" href="#register1"><span class="icon-user"></span>Register
      </a>   
   </li>
</ul>
<div class="tab-content">
   <div id="login1" class="tab-pane active">
      <input type="text"> <!-- focus when tab clicked -->
   </div>
   <div id="register1" class="tab-pane">
      <input type="text"> <!-- focus when tab clicked -->
   </div>
</div>

The first input field will not be automatically focused you can do the following: 第一个输入字段不会自动聚焦,您可以执行以下操作:

$('input').first().focus();

This will focus the input field. 这将集中输入字段。 You might even want to do it on document ready as an initiation script, like so: 您甚至可能希望将其作为初始化脚本在准备好的文档上进行处理,如下所示:

$(function() {
    $('input').first().focus();
});

Do it manually if you want.. 如果需要,请手动执行。

$(document).ready(function(){
    $(".tab-pane").on('click', function(){
        $(this).find("input[type=text]").filter(':visible:first').focus();
    });
});

Hoe that helps.. e头有帮助..

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

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