LayuI 动态下拉框和动态设置选中

动态下拉框

//下拉框异步加载
function asyncSelect(thisId, grade, selectNodeName) {
    $("#" + selectNodeName + "").empty();
    $("#" + selectNodeName + "").append("<option value=''>请选择</option>");
    //异步加载二级选项
    $.ajax({
        url: this_URL,
        type: "get",
        dataType: "json",
        success: function (rep) {
            let result = rep.data;
            //一级菜单初始化
            $.each(result, function (index, item) {
                $("#" + selectNodeName + "").append(new Option(item.static_name, item.xline_id));
            });
            layui.form.render("select");
        }
    });
}

设置下拉框某个选项选中

  $("#下拉框ID").val("被选项value");
  layui.form.render("select");

ajax常规格式

 $.ajax({
            //请求方式
            type: "POST",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url: ctx + This_Url,
            //数据,json字符串
            data: JSON.stringify(date),
            traditional: true,
            //请求成功
            success: function (result) {
			//toDo
		} //请求失败,包含具体的错误信息
            error: function (e) {
                alert("失败发送");
                console.log(e.status);
                console.log(e.responseText);
            }
	});

数据表达 双击

 //双击事件::修改
    table.on('rowDouble(test)', function (obj) {
		//obj.data  整行数据信息
		//toDO。。。。。。

    });

时间选择器

HTML:
 <input type="text" class="layui-input" name="audit_time" id="test8" placeholder="yyyy-MM-dd HH:mm:ss">
CSS:
 //日期时间选择器
    laydate.render({
        elem: '#test8'
        , type: 'datetime'
    });

时间格式化常规

//2020-02-11T12:24:18.000+0000转化成正常格式 yyyy-MM-dd HH:ss:mm
function renderTime(date) {
    var dateee = new Date(date).toJSON();
    return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
}

数据表格字段翻译 :templet

sort: true, //排序
fixed: 'left', //靠左
hide: true //隐藏

		{
                field: 'state',
                title: '状态',
                width: 100, templet: function push_time(d) {
                    if (d.state == 0)
                        return "无效";
                    else if (d.state == 1)
                        return "有效";
                    else
                        return "删除";
                }

posted on   白嫖老郭  阅读(1914)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示