简体   繁体   English

按钮中的下拉菜单值

[英]Dropdown menu values in button

This is a drop-down menu I want to display the values in the button on the base of value selected from the list.. Screenshot is attached for reference. 这是一个下拉菜单,我要在从列表中选择的值的基础上显示按钮中的值。.随附屏幕截图以供参考。 What is the best approach to do this? 最好的方法是什么?

<button 
    type="button" 
    class="btn btn-fit-height grey-salt dropdown-toggle" 
    data-toggle="dropdown" 
    data-hover="dropdown" 
    data-delay="1000" 
    data-close-others="true">

        //Where Value 1 is written I want the li values..
        Value 1
        <i class="fa fa-angle-down"></i>
</button>

<ul class="dropdown-menu pull-right" style="margin-right:15px" role="menu">
    <li><a href="#">Value 1</a></li>
    <li><a href="#">Value 2</a></li>
    <li class="divider"></li>
    <li><a href="#">Value 3</a></li>
    <li><a href="#">Value 4</a></li>
    <li><a href="#">Value 5</a></li>
    <li><a href="#">Value 6</a></li>
</ul>

在此处输入图片说明

You could do 你可以做

$(function() {
    var $button = $('button'); // maybe better give it an id or something

    $('.dropdown-menu.pull-right a').on('click', function(e) {
        e.preventDefault();

        $button.text($(this).text());
    });
});

But you have to make a valid HTML (button has to be closed) 但是您必须制作有效的HTML(必须关闭按钮)

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

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