如何使用Chosen JQuery插件获取所选项目?

时间:2014-05-11 10:31:40

标签: javascript jquery

我正在使用我的多选框,但我不知道如何获取所选项目?

  <select class="multiselect" multiple="" name="parlementId">           
        @foreach (Politicus p in politici)
        { 
            <option value="@p.politicusID">@Html.DisplayName(p.Account.voornaam.ToString())</option>
        }

  </select> 

  $('.multiselect').chosen({ width: '500px', allow_single_deselect: true, max_selected_options: 5 });

  $('.multiselect').on('change', function (evt, params) {
       //this is where I need to know which options are selected
  });

1 个答案:

答案 0 :(得分:1)

你可以这样:

var values = $(".multiselect").chosen().val();
// this will give you values in an array

请参阅Documentation here

或:

 var values = $(".multiselect").val();