简体   繁体   English

我尝试向其中添加Bootstrap下拉按钮, <a>但下拉菜单无法正常工作。</a> <a>我该怎么做呢?</a>

[英]I tried to add a Bootstrap dropdown button to <a> but the dropdown menu wont work. How do I do this?

<li><a href="#" class=" dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">CONTACT<span class="caret"></span></a>    
    </li>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
        </ul>

Can someone please help me. 有人可以帮帮我吗。 everything in is from bootstrap's website. 一切都来自bootstrap网站。 Heres the whole html file http://pastebin.com/YXsVPRhz 这是整个html文件的http://pastebin.com/YXsVPRhz

You're missing the data-target from the a.dropdown-toggle , and an id for the targeted ul . 您缺少a.dropdown-toggledata-target ,以及目标ulid

For the a , add a data-target attribute which is the id of the ul : 对于a ,添加一个data-target属性,它是ul的ID:
data-toggle="dropdown" //sample name

For the ul , add an id: 对于ul ,添加一个ID:
id="dropdown" //sample name

so it should be: 所以应该是:

<li><a href="#" class=" dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" data-target="dropdown-menu" aria-expanded="true">CONTACT<span class="caret"></span></a>    
    </li>
        <ul class="dropdown-menu" id="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
        </ul>

Add the ul as a sibling of the anchor ul添加为锚的同级

<li>
    <a href="#" class=" dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">CONTACT<span class="caret"></span></a> 
    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a>
        </li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a>
        </li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a>
        </li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a>
        </li>
    </ul>
</li>

Demo: Fiddle 演示: 小提琴

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

相关问题 如何使用DropDown Value onClick Button跟踪动态网址-为什么不起作用? - How do I follow dynamic url with DropDown Value onClick Button - why wont this work? 如何为 Bootstrap 4 滑动下拉菜单设置动画? - How do I animate a Bootstrap 4 sliding dropdown menu back up? 如何使用上一个和下一个按钮遍历带有嵌套下拉菜单的Bootstrap选项卡式导航菜单? - How do I traverse a Bootstrap tabbed navigation menu with nested dropdown using prev and next button? 如何在引导程序上触发下拉按钮模糊/关闭事件? - How do I trigger a dropdown button blur / close event on bootstrap? 如何将工具栏按钮添加到自定义的下拉菜单中? - How do I add toolbar buttons to a custom tinymce dropdown menu? Bootstrap 4:单击下拉项时如何关闭下拉菜单? - Bootstrap 4: How Do I Close a dropdown-menu when a dropdown-item is clicked? 我如何在dynamicjs中创建一个下拉菜单 - How do I create a dropdown menu in kineticjs 如何在html中创建下拉菜单? - How do I make a dropdown menu in html? 如何隐藏下拉菜单? - How do I hide my dropdown menu? Bootstrap 4:单击菜单选项后如何关闭主下拉导航栏? - Bootstrap 4: How Do I Close The Main Dropdown Navbar after clicking a Menu Option?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM