[toc] # layer的妙用 ## 1.输入框prompt改远程选择(selectpage) **效果** ![](https://img.kancloud.cn/1e/91/1e91f9332651b723d76f0357f9c6c836_353x194.png) **代码** ``` Layer.prompt({ title: '请选择下派到的工作人员', success: function (layero) { $("input", layero).addClass("selectpage") .data("source", "auth/admin/mychildren") .data("primaryKey", "id") .data("field", "nickname") .data("orderBy", "id desc") .data("selectOnly", "true") .prop("placeholder", "请选择"); Form.events.selectpage(layero); } }, function(value, index, elem){ var userId = $('input[name="selectPage"]').val(); // your code~ layer.close(index); }); ``` ## 2.确认框改多个操作选择 **效果** ![](https://img.kancloud.cn/c5/b7/c5b750daeec000012d39e91ef2e13853_462x268.png) **代码** ``` // 排房 $(document).on('click', '.btn-assign-room', function() { const ids = Table.api.selectedids(table); // bootstrapTable选中项目ids const data = table.bootstrapTable("getAllSelections"); // 选中的数据 const create_nu = data[0].create_nu; Layer.confirm("请选择操作对象", { title: "排房", btn: ["选中项(" + ids.length + "条)", "本批次 (" + create_nu + ")"], success: function (layero, index) { $(".layui-layer-btn a", layero).addClass("layui-layer-btn0"); // 所有按钮统一颜色 }, yes: function (index, layero) { // 操作1 }, btn2: function (index, layero) { // 操作2 }, }); return false; }); ```