How do I get selected value from a bootstrap select drop down

前端 未结 3 1969
盖世英雄少女心
盖世英雄少女心 2021-01-01 14:59

I\'m trying to get the selected text, not value, from my bootstrap drop down, but my .text() statement is returning a string that contains all the values with a \'\\n\' in b

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 15:30

    You can get the selected value's text with $(this).find("option:selected").text().

    $('#SpaceAccommodation').change(function () {
        var selectedText = $(this).find("option:selected").text();
        
        $(".test").text(selectedText);
    });
    
    
    

提交回复
热议问题