Chosen Jquery Plugin - getting selected values

2019-01-21 06:20发布

How can i get the selected values from the chosen Multi-select Box?

8条回答
小情绪 Triste *
2楼-- · 2019-01-21 06:47
$("#select-id").chosen().val()
查看更多
SAY GOODBYE
3楼-- · 2019-01-21 06:48

This worked for me

$(".chzn-select").chosen({

     disable_search_threshold: 10

}).change(function(event){

     if(event.target == this){
        alert($(this).val());
     }

});
查看更多
beautiful°
4楼-- · 2019-01-21 06:52

As of 2016, you can do this more simply than in any of the answers already given:

$('#myChosenBox').val();

where "myChosenBox" is the id of the original select input. Or, in the change event:

$('#myChosenBox').on('change', function(e, params) {
    alert(e.target.value); // OR
    alert(this.value); // OR
    alert(params.selected); // also in Panagiotis Kousaris' answer
}

In the Chosen doc, in the section near the bottom of the page on triggering events, it says "Chosen triggers a number of standard and custom events on the original select field." One of those standard events is the change event, so you can use it in the same way as you would with a standard select input. You don't have to mess around with using Chosen's applied classes as selectors if you don't want to. (For the change event, that is. Other events are often a different matter.)

查看更多
叼着烟拽天下
5楼-- · 2019-01-21 06:53

Like from any regular input/select/etc...:

$("form.my-form .chosen-select").val()
查看更多
可以哭但决不认输i
6楼-- · 2019-01-21 06:58

If anyone wants to get only the selected value on click to an option, he can do the follow:

$('.chosen-select').on('change', function(evt, params) {
    var selectedValue = params.selected;
    console.log(selectedValue);
});
查看更多
手持菜刀,她持情操
7楼-- · 2019-01-21 06:59
$("#select-id").chosen().val()

this is the right answer, I tried, and the value passed is the values separated by ","

查看更多
登录 后发表回答