简体   繁体   English

为什么我的Bootstrap 3.1.1'Collapse'元素会自动关闭?

[英]Why does my Bootstrap 3.1.1 'Collapse' element automatically close?

I've been having trouble with my mobile menu/navbar. 我的移动菜单/导航栏遇到了麻烦。 I created a 'Sign in' button that drops down with a log in form using collapse.js that's provided by Bootstrap. 我创建了一个“登录”按钮,该按钮使用Bootstrap提供的crash.js下拉到一个登录表单。 My div pulls down and collapses perfectly. 我的div下拉并完美崩溃。 However, for whatever reason it automatically collapses back up whenever you click on the username or password text box fields. 但是,无论出于何种原因,只要您单击用户名或密码文本框字段,它就会自动折叠起来。 Any idea why this is happening? 知道为什么会这样吗?

Here's a link to the jsfiddle to demonstrate this issue: http://jsfiddle.net/65KdX/2/ 这是演示此问题的jsfiddle链接: http : //jsfiddle.net/65KdX/2/

Here is the section of code that is for the navbar: 这是用于导航栏的代码部分:

<!-- Begin Navbar items -->
      <div class = "collapse navbar-collapse" id = "mainNavbarInfo">
        <ul class = "nav navbar-nav navbar-right">
          <li class = "active"><a href = "#"><span class = "glyphicon glyphicon-home"></span> Home </a> </li>
          <li><a href = "#"><span class = "glyphicon glyphicon-list-alt"></span> SLO Generator </a> </li>
          <li><a href = "#"><span class = "glyphicon glyphicon-question-sign"></span> SLO Tutorial </a> </li>
          <li><a href = "#"><span class = "glyphicon glyphicon-cloud-upload"></span> Sign Up  </a></li>

          <li data-toggle = "collapse" data-target = "#signInFormCollapseMobile" class = "visible-xs">
            <a href = "#"><span class = "glyphicon glyphicon-share-alt"></span> Sign In<div class = "collapse signInFormCollapse" id = "signInFormCollapseMobile" style = "position: relative;"></a>
              <form action="[YOUR ACTION]" method="post" accept-charset="UTF-8" id = "signInFormMobile">
                  <input id="user_username" style="margin-bottom: 15px; margin-top: 10px;" type="text" name="user[username]" size="30" placeholder = "Username"/>
                  <br><input id="user_password" style="margin-bottom: 15px;" type="password" name="user[password]" size="30" placeholder = "Password"/>
                  <br><input id="user_remember_me" style="float: left; margin-right: 10px;" type="checkbox" name="user[remember_me]" value="1" />
                  <label class="string optional" for="user_remember_me"> Remember me</label>

                  <input class="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px; margin-bottom: 10px;" type="submit" name="commit" value="Sign In" />
              </form>
            </div>
          </li>
       </ul>

      </div>

The problem is that your form is nested within that <li> block. 问题在于您的form嵌套在该<li>块中。

If you move the div that contains the form outside the <ul> section, it works fine. 如果将包含formdiv移动到<ul>部分之外,则可以正常工作。

See this updated jsfiddle . 请参阅此更新的jsfiddle

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

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