Twitter Bootstrap: How do I get the selected value of dropdown?

后端 未结 4 1655
暗喜
暗喜 2021-02-05 16:33

I need to get the value a user selects from a twitter bootstrap dropdown. Once the user selects a value I want the dropdown to display that value. So, the user selects \'pending

相关标签:
4条回答
  • 2021-02-05 16:52

    Bootstrap provides you with minimum required functionality for your implementation, they aren't dropdowns instead they are mere ul, li's with css applied on it and some events registered in the bootstrap plugin for toggling the button to display them as dropdown. This one you need to do on your own.

    Set up some identifier to the status button say a className btnStatus and bind a click event to the dropdown links. and do something like this?

    $('.dropdown-inverse li > a').click(function(e){
        $('.btnStatus').text(this.innerHTML);
    });
    

    Demo

    0 讨论(0)
  • 2021-02-05 16:52

    I had the same issue. The solution is pretty easy and I think the answers above may be overcomplicating a bit.

    Just use $(this).text()

    Assign a class name to the "" bit then..

    $(".yourUlClassName li a").click( function() {
        var yourText = $(this).text();
    });
    
    0 讨论(0)
  • 2021-02-05 16:52

    you can try this:

    u can use class or id for selector to select easier the element. for use the value also u can use the value in u javascript with jQuery.

        $().ready(function(){
            $('a').click(function(){
                var value = $(this).text();
                alert(value);
            });
        });
    

    Demo: http://jsfiddle.net/mr_mohsen_rasouli/A8m39/

    0 讨论(0)
  • 2021-02-05 16:53

    Try like this -

    $(document.body).on('click', '.dropdown-menu li a', function (e) {
        alert($(this).text());
    });
    

    Demo - Fiddle

    0 讨论(0)
提交回复
热议问题