Display Selected Item in Bootstrap Button Dropdown Title / place holder text

后端 未结 2 826
情书的邮戳
情书的邮戳 2021-02-08 21:12

This question has been asked a few times on Stackoverflow - however I still cant get to the bottom of it... plus my query is throwing more dropdowns into play. So I have two dro

相关标签:
2条回答
  • 2021-02-08 21:21

    Bootstrap 4 version:

    $(".dropdown-item").click(function(){
        var selText = $(this).text();
        $(this).parents('.dropdown').find('.dropdown-toggle').html(selText+'<span class="caret"></span>');
    });
    
    0 讨论(0)
  • 2021-02-08 21:28

    You can set the selected dropdown text like this..

    $(".dropdown-menu li a").click(function(){
      var selText = $(this).text();
      $(this).parents('.btn-group').find('.dropdown-toggle').html(selText+'<span class="caret"></span>');
    });
    

    And then handle the search button click to get the selected values:

    $("#btnSearch").click(function(){
        alert($('.btn-select').text()+", "+$('.btn-select2').text());
    });
    

    Working demo: http://www.bootply.com/63926

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