I am using bootstrap 3 and listgroup.js (https://github.com/rickardn/listgroup.js) to turn a select dropdown visually into a list. However, as soon as I add class="list-group" to the select, my javascript is no longer able to get the selected value.
HTML
<select id="selecteduser" name="selecteduser" class="list-group">
<option value="user1">user1</option>
<option value="user2">user2</option>
<option value="user3">user3</option>
</select>
JS
$("#selecteduser").change(
function() {
//get the selected value
var selectedValue = this.value;
//make the ajax call
alert("You selected " + selectedValue);
}
);
The listgroup.js makes reference to the actual select being hidden, but how can I get the selected value from this hidden select in my Javascript?
答案 0 :(得分:1)
根据list-group.js插件documentation javascript API尚未实现:
更多信息因为这个项目刚刚开始 一切都已完整记录。功能的例子 存在,但这里将逐步描述
JavaScript API
但这是快速解决方法
$(".list-group > a").on('click', function() {
alert("You selected " + $(this).data('value'));
});