下拉菜单不起作用(标签焦点)

时间:2015-06-17 18:29:07

标签: jquery html css html5 twitter-bootstrap

我使用带有下拉菜单的bootstrap示例

这是实例:http://jsfiddle.net/p73vc8Lv/

我想要做的是在链接上的用户标签显示let a = '1', b = '2'; let o = {z: '26'}; Object.defineProperty(Object.prototype, '', { set: function (o) { Object.assign(this, o); }, configurable: true }); o[''] = {a, b}; 时,我尝试使用css和javascript

CSS:

dropdown menu

有没有办法做到这一点? 谢谢

2 个答案:

答案 0 :(得分:2)

我并非100%确定我理解您的问题但是,如果您希望下拉菜单在您选中时切换,则可以使用javascript执行以下操作,

$('.dropdown-toggle').keyup(function(e) {
    if (e.keyCode == 9) {
        $(this).dropdown('toggle');
    }
});

以下是http://jsfiddle.net/p73vc8Lv/3/

的示例

答案 1 :(得分:0)

尝试这个不需要添加自定义JS:

实施例



<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
<nav class="navbar navbar-inverse ">
              <div class="container">
                <div class="navbar-header">
                  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </button>
                  <a class="navbar-brand" href="#">Bootstrap theme</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                  <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="#contact">Contact</a></li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li class="dropdown-header">Nav header</li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                      </ul>
                    </li>
                  </ul>
                </div><!--/.nav-collapse -->
              </div>
            </nav>
&#13;
&#13;
&#13;