LOT.UI分解系列匯總:http://www.cnblogs.com/dunitian/p/4822808.html#lotui
LoT.UI開源地址如下:https://github.com/dunitian/LoTCodeBase/tree/master/LoTUI
這個必須說下,本來是用Bootstrap-Select做的,很漂亮,正好后臺也是Bootstrap。后來發現不能滿足需求。標簽有則選,沒則添加?而Bootstrap-Select的文本框是不可以手動輸入的==》so,用了Select2,這個可以不依賴Bootstrap
兩種我都做了Demo,至于取舍就看你自己了~
先看在LoT.UI里面的應用效果圖:
Bootstrap-Select:(諸如權限分配,菜單分配都可以用)
--------------------------------------------------------------------------------------------------------------------------------------------------------
Select2:(通用,但丑了點。可后期美化)
----------------------------------------------------------------------------------------------------------------------------------------------------------
Bootstrap-Select 演示(https://github.com/dunitian/LoTCodeBase/blob/master/LoTUI/Manager/Demo/select.html)
BootStrap-Select我這邊就不具體說了,demo里面有演示,這邊說下Select2
核心代碼(https://github.com/dunitian/LoTCodeBase/blob/master/LoTUI/Manager/Demo/select2.html)
1.樣式部分:
2.HTML部分
3.Script部分
完整代碼:
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><meta charset="utf-8" /><link href="/open/select2/select2.min.css" rel="stylesheet" />
</head>
<body><select style="width:50%;" id="lot-tagSelect" multiple><optgroup label="SQL"><option>MySql</option><option>Sqlite</option><option>SQLServer</option></optgroup><optgroup label="Other"><option>C#</option><option>EF</option><option>MVC</option><option>Dapper</option><option>Ado.Net</option></optgroup></select><button id="btn">獲取選中項的值</button><script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script><script src="/open/select2/select2.min.js"></script><script type="text/javascript">$('#lot-tagSelect').select2({tags: true,tokenSeparators: [',', ' ']});$('#btn').click(function () {var ids = $.map($('#lot-tagSelect').select2("data"), function (row) {return row.text;});alert(ids.join(','));});</script>
</body>
</html>
開源組件:
https://github.com/silviomoreto/bootstrap-select
https://github.com/select2/select2