博客:
基于Metronic的Bootstrap开发框架经验总结(3)--下拉列表Select2插件的使用
<div class="span4 channelSearch"> <div class="input-control select size3"> @Html.DropDownList("ChannelIds", Model.Channels.Select(c => new SelectListItem { Text = c }), new { style = "100%;height:22px", multiple = "multiple" }) </div> </div>
$("#ChannelIds").select2({ placeholder: 'This is my placeholder' , allowClear: true }); $("#ChannelIds").val(campaignIds.split(",")).trigger('change');
添加全选:
$('.select-all').on('select2:opening', function (e) { var $this = $(this); if ($this.children(".optionAll").length==0) { $this.prepend("<option class='optionAll' value='-100'>---全选----</option>"); } }); $('.select-all').on('select2:select', function (e) { var $this = $(this); if (e.params.data.id == "-100") { EntityOperation.selectAllSelect2($this); } });