需要引用的JS
jquery.js, bootstrap.js, doublebox-bootstrap.js
需要引用的CSS
bootstrap.css, font-awesome.css, doublebox-bootstrap.css
调用接口
var doubleboxdemo = $('.demo').doublebox({ nonSelectedListLabel: '选择角色', selectedListLabel: '授权用户角色', preserveSelectionOnMove: 'moved', moveOnSelect: false, nonSelectedList: [{ "roleId": "1", "roleName": "zhangsan" }, { "roleId": "2", "roleName": "lisi" }, { "roleId": "3", "roleName": "wangwu" }], selectedList: [{ "roleId": "4", "roleName": "zhangsan1" }, { "roleId": "5", "roleName": "lisi1" }, { "roleId": "6", "roleName": "wangwu1" }], optionValue: "roleId", optionText: "roleName", doubleMove: true, });
var selectedText = new Array(); var selectedOption = new Array(); $('select[name="doublebox"]').find("option:not(:selected)").each(function(index, item) { selectedText[index] = $(item).text(); selectedOption[index] = $(item).val(); });
这是获取未选中的所有的值
$('select[name="doublebox"]').find("option:selected").each(function(index, item) { selectedText[index] = $(item).text(); selectedOption[index] = $(item).val(); });
这是获取已选中的值 希望对大家有所帮助