jQuery MultiSelect Widget Demo
//下拉列表元素 所属行业: @Html.MultiselectDropDownListFromDict("SdaptIndustry", new { @class = "inputClass", @multiple = "multiple" }, "SdaptIndustry") //初始化下拉列表信息$(function () { $("#SdaptIndustry").multiselect({ noneSelectedText: "请选择", checkAllText: "全选", uncheckAllText: '全不选', selectedText: '已选择#项', selectedList: 6 }); });//Ajax 实现信息添加 var profile = UE.getEditor('CommProfile').getContent(); $.ajax({ url: "/Commodity/Add", type: 'POST', data: { SdaptIndustry: "" + $('#SdaptIndustry').val(), SdaptIndustryName: "" + $("#SdaptIndustry").multiselect("getSelectedText"), SdaptBusDomain: "" + $('#SdaptBusDomain').val(), SdaptBusDomainName: "" + $('#SdaptBusDomain').multiselect("getSelectedText"), }, success: function (data) { if (data.success) { alert("添加成功!"); //$("#rightDiv").load("/Commodity/ManageIndex", "", function () { }); window.location.href = "ManageIndex"; } else alert(data.message); }, dataType: "json", }); }
修改信息:
//数据库信息,显示到下拉列表选中 var ids = '@Model.SdaptIndustry'.split(","); $('#SdaptIndustry option').each(function (i, content) { //alert(i+"***"+content.value); if ($.inArray($.trim(content.value), ids) >= 0) { this.selected = true; } }); $("#SdaptIndustry").multiselect({ noneSelectedText: "请选择", checkAllText: "全选", uncheckAllText: '全不选', selectedText: '已选择#项', selectedList: 6 });