
layui提交post:
table.js
//表格属性:page,elem,url,cols
//列属性:type,field,title
table.render({
        //1 开启分页
        page: true,
        //2 指定渲染的table容器
        elem: '#articleList',
        //3 异步访问的路径
        url: '../../user',
        //4 集合属性
        cols: [[
            {type: 'checkbox'},
            //4.1   普通属性
            {field: 'username', title: '用户名称',width:'11%'},
            //4.2   单选框属性
            {field: 'sex',      title: '性别',    width:'11%'},
            //4.3   复选框属性
            {field: 'status',   title: '状态',    templet: '#status',width:'11%'},
            //4.4   日期属性
            {field: 'updated',  title: '最近修改时间',width:'14%',
                //日期格式转化
                templet: function createTime(d){
                            return new Date(parseInt(d.updated)).toLocaleString()
                 }
            },  
        ]]
        
        //4.2   数字条件判断
        ,done:function(res,curr,count){
            $("[data-field='sex']").children().each(function(){
                //若选取元素为1
                if($(this).text() == '1'){
                     
                    $(this).text('男');
                //若选取元素为0
                }else if($(this).text() == '0'){
                    
                    $(this).text('女');
                }
            });
        }
    });
    //4.4   调用的日期格式转化器
     Date.prototype.toLocaleString = function() {
        var y = this.getFullYear();
        var m = this.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = this.getDate();
        d = d<10?("0"+d):d;
        var h = this.getHours();
        h = h<10?("0"+h):h;
        var M = this.getMinutes();
        M = M<10?("0"+M):M;
        var S=this.getSeconds();
        S=S<10?("0"+S):S;
        return y+"-"+m+"-"+d;
        /*+" "+h+":"+M+":"+S*/
    };post.js
$.post(
    //1 异步提交的urL
    '${pageContext.request.contextPath}/user/add',
    //2 form表单以键值对形式传输
    data.field,
    //3 访问后成功的回调函数
    function (data) {
        if (data > 0) {
            //3.1   弹窗提示
            layer.msg("添加成功!", {icon: 1});
            //3.2  获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //3.3   关闭当前frame
            parent.layer.close(index);
            //3.4   刷新页面
            window.parent.location.reload();
        }else{
            layer.msg("添加失败!", {icon: 1});
        }
    }
);推荐:layui框架教程
相关文章推荐:1.layui和后端如何连起来 2.layui抓取表单数据相关视频教程:1.JavaScript极速入门_玉女心经系列
以上就是layui如何提交post的详细内容,更多请关注php中文网其它相关文章!
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                
                                
                                
                                
                                
                                
                                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号