0

阅读 twitter bootstrap on dropdowns 的文档,我看到它说你可以让 url 在下拉切换时保持不变。我试图做到这一点,但没有任何运气。相反,它只是切换下拉菜单而不是它应该进行的路径。我错过了什么?这是我的代码示例。

<li class="dropdown">
  <a class="dropdown-toggle" id="dPublisher" data-toggle="dropdown" role="button" data-target="#" href="publisher.php">PUBLISHER<b class="caret"></b></a>
    <ul class="dropdown-menu" role="menu" aria-labelledbyid="dPublisher">
        <li><a href="eeditions.php">E-Editions</a></li>
    <li><a href="digitalarchive.php">Digital Archive</a></li>
    </ul>
</li>
<li><a href="blog.php">BLOG</a></li>

在此示例中,PUBLISHER 应该是下拉触发器和链接,而 BLOG 只是一个链接。下拉菜单有效,内部的所有链接都有效,但我无法像文档中所说的那样让 url 保持完整。我不理解文档吗?

任何帮助将不胜感激!

4

1 回答 1

0

You can use the onClick event, as mentioned, but you'll want it disabled for mobile views. If you're using the Bootstrap navBar, for instance, you can do the following after adding a ".clickable-dropdown" class to your toggle trigger:

                $(document).ready(function(){
                    $(window).resize(function(){
                        if($(window).width() >= 920){
                            $('.clickable-dropdown').on('click', function(){
                                window.location.href=$(this).attr('href');
                            });
                        }else{
                            $('.clickable-dropdown').on('click', function(){
                                return false;
                            })
                        }
                    }).resize();
                });

This will allow the drop-down to work on mobile devices with the touch event, and not capture the click's normal function. Unfortunately, this seems to be a limitation of Bootstrap's dropdown script and if you need better functionality, you're better off just using one of the many other CSS or jQuery based drop-down menus.

于 2015-01-26T04:02:58.887 回答