【问题标题】:Bootstrap dropdown disappears on input selectBootstrap 下拉菜单在输入选择时消失
【发布时间】:2013-04-17 11:15:48
【问题描述】:

我有一个我打算用来登录的 Bootstrap 下拉菜单。它看起来很好,但是当我选择用户名 nput 时它消失了,因为焦点已经转到输入。我将如何着手添加对输入的支持,或者是否有可行的方法?

我当前的代码是:

    <li id="fat-menu" class="dropdown">
         <a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown" data-target="#">Login <b class="caret"></b></a>
         <ul class="dropdown-menu" role="menu" aria-labelledby="drop3">
            <li role="presentation"><input name="username" type="text" placeholder="Username" /></li>
            <li role="presentation"><input name="password" type="password" placeholder="Password" /></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Login</a></li>
          </ul>
     </li>

我对 jsfiddle 的尝试。我根本无法让下拉菜单工作:http://jsfiddle.net/KF8dv/

【问题讨论】:

标签: jquery html css twitter-bootstrap


【解决方案1】:

请看这个:- http://jsfiddle.net/b8769/

当点击输入文本框时,您需要防止下拉事件。您可以使用 javascript 来实现这一点。 stopPropagation

$('.dropdown-menu input').click(function(e) {
        e.stopPropagation(); //This will prevent the event from bubbling up and close the dropdown when you type/click on text boxes.
    });

【讨论】:

  • 很好!!快速解决。感谢您的回答!
  • 当你为任何引导程序编写 js fiddle 时,你可以使用引导程序的 CDN 路径作为外部 URL。bootstrapcdn.com
  • 按钮现在似乎通​​过了点击测试,并没有消失。但是点击后如果我点击其他地方它会再次消失..
猜你喜欢
  • 2019-10-30
  • 1970-01-01
  • 2013-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多