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

前端 未结 3 1997
盖世英雄少女心
盖世英雄少女心 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:18

    In case anyone cares, I've got another solution. I just looked at the arguments from the docs. You can do something like this (Assuming you've set the value tag of the option element.:

     $('#type_dropdown')
                    .on('changed.bs.select',
                        function(e, clickedIndex, newValue, oldValue) {
                            alert(e.target.value);
                        });
            });
    

    See https://silviomoreto.github.io/bootstrap-select/options/

提交回复
热议问题