/**
* 一键生成“搜索”
* @param json
*/
function buildSearch(json,extra = null) {
var content = `<form action="" class="layui-form search-form" style="float:left;">`;
$.each(json, function (index, item) {
content += `<div class="layui-inline">`;
//第一条数据得加上label, 作为开始的标签
if (index == 0 && item.label) {
content += `<span class="data-screening-title">` + item.label + ` </span>`;
}
//下拉框
if (item.type == 'select') {
content += `<div class="layui-input-inline"><select name="` + item.name + `" lay-filter="" class="layui-input layui-input-inline">`;
$.each(item.data, function (key, value) {
if (item.selected == key) {
content += `<option value="` + key + `" selected="selected">` + value + `</option>`;
} else {
content += `<option value="` + key + `">` + value + `</option>`;
}
});
content += `</select></div>`;
} //text 框
else if (item.type == "text") {
//开始日期前加上label:
if (item.id == "start-date") {
content += `<span class="data-screening-title">开始日期:</span>`;
}
//结束日期前加上 -
if (item.id == "end-date") {
content
js封装,实现调用接口生成HTML表单页面
最新推荐文章于 2024-09-06 17:19:50 发布