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

后端 未结 2 827
情书的邮戳
情书的邮戳 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: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+'');
    });
    

    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

提交回复
热议问题