简体   繁体   English

单击下拉菜单按钮时,引导程序打开链接

[英]Bootstrap open link when clicked on dropdown menu button

I used bootstrap in my main menu and since my project has a lot of pages, subpages and sub-subpages I used the bootstrap dropdownmenu to navigate through this. 我在主菜单中使用了bootstrap,因为我的项目有很多页面,子页面和子子页面,所以我使用了bootstrap dropdownmenu来浏览它。

My client now wants to be able to go to the link associated with the dropdown-button itself too, rather than the childen. 我的客户现在希望能够转到与下拉按钮本身相关联的链接,而不是孩子。 My client has text on a page called 'customer support', and text on subpages (children). 我的客户在名为“客户支持”的页面上有文本,在子页面(子项)上有文本。 Ideally I want the user to first click a dropdownmenu button (ex. "Customer service"), and a dropdownmenu opens up (which Bootstrap does), and on a second click be able to go to the link associated with that dropdownmenu button (ex. "/customer-service"). 理想情况下,我希望用户首先单击一个下拉菜单按钮(例如“客户服务”),然后打开一个下拉菜单(Bootstrap会这样做),然后第二次点击就可以转到与该下拉菜单按钮相关联的链接(例如。 “/客户服务”)。

I'll share some code to make it a bit more understandable: 我将分享一些代码,使其更容易理解:

<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="/customer-service" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>

                    <!-- click this menu-button once, and the submenu below opens, click this menu-button twice and you go to /customer-service -->
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li><a href="#">Something else here</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>

                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Action</a>
                        </li>
                        <li><a href="#">Another action</a>
                        </li>
                        <li><a href="#">Something else here</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

http://jsfiddle.net/kozog9rx/2/ http://jsfiddle.net/kozog9rx/2/

(be sure to read the comment in the HTML and give the "Result-view" enough space/width so the menu appears) (务必阅读HTML中的注释并给出“结果 - 视图”足够的空间/宽度,以便显示菜单)

Well, assuming you are using bootstrap 3.2.0 Here's the code: 好吧,假设您正在使用bootstrap 3.2.0这是代码:

<li class="dropdown">
   <a href="example.com/page">Dropdown</a>
   <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>    
   <ul class="dropdown-menu" role="menu">
      <li><a href="#">Action</a></li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li><a href="#">Separated link</a></li>
      <li class="divider"></li>
      <li><a href="#">One more separated link</a></li>
   </ul>
</li>

What i'm doing is making the carat open the menu, and the text href to wherever you want it to go to. 我正在做的是让克拉打开菜单,文本href到你想要的地方。

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

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