Chosen Jquery Plugin - getting selected values

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

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

回答1:

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

$("form.my-form .chosen-select").val() 


回答2:

$("#select-id").chosen().val() 


回答3:

This worked for me

$(".chzn-select").chosen({       disable_search_threshold: 10  }).change(function(event){       if(event.target == this){         alert($(this).val());      }  }); 


回答4:

$("#select-id").chosen().val() 

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



回答5:

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); }); 


回答6:

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.)



回答7:

if you want to get text of a selected option (chosen get display selected value)

 $("#select-id").chosen().find("option:selected" ).text(); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!