例如多選框以下:html
<div class="layui-form"> <select xm-select="city"> </select> </div>
動態加載:數組
var url = "加載路徑"; View.get(url, "city=" + city, function(resp) { if (resp) { var html = ""; for (var i = 0; i < resp.length; i++) { html += "<option value='" + resp[i].key + "'>" + resp[i].value +"</option>"; } $("select[xm-select='city']").html(html); } layui.formSelects.render();// 從新渲染多選框 }, function() { });
從新渲染多選框:ui
layui.formSelects.render();
例如多選框以下:url
<div class="layui-form"> <select name="city" xm-select="city_2"> <option value="1" selected="selected">北京</option> <option value="2">上海</option> <option value="3">廣州</option> <option value="4">深圳</option> <option value="5">天津</option> </select> </div>
禁用:spa
$("select[xm-select='city_2']").attr("disabled", "disabled"); layui.formSelects.render();
啓用:orm
$("select[xm-select='city_2']").attr("disabled", false); layui.formSelects.render();
賦值:htm
layui.formSelects.value('city_2', []); //賦值空數組, 清空全部 layui.formSelects.value('city_2', [1, 2]); //賦值 北京,上海 layui.formSelects.value('city_2', [5], true); //追加賦值 天津 layui.formSelects.value('city_2', [1], false); //刪除 已選擇 [北京]
取值:blog
layui.formSelects.value('city_2'); //取值默認數組 layui.formSelects.value('city_2', 'val'); //取值val數組 layui.formSelects.value('city_2', 'valStr'); //取值val字符串 layui.formSelects.value('city_2', 'name'); //取值name數組 layui.formSelects.value('city_2', 'nameStr'); //取值name字符串
取值結果:ci
取值默認數組:[{"name":"北京","value":"1"}]文檔
取值val數組:["1"]
取值val字符串:"1"
取值name數組:["北京"]
取值name字符串:"北京"
詳細官網文檔:https://fly.layui.com/extend/formSelects/
http://sun.faysunshine.com/layui/formSelects-v4/example/example_v4.html