layui动态添加表格

layui动态添加表格,第1张

+ '请求参数'
+ ''
+ ''+''+''+''+''+''+''+''+''+''+''+''+'
参数 是否必须 默认值 含义 *** 作
'
layui.use(['jquery', 'form', 'laydate', 'layer'], function () {
    var $ = layui.$,
    layer = layui.layer,
    form = layui.form,
    $view = $('#apidocument_add_form'),
    requestIndex = 1,
    responseIndex = 1;

    form.render();

    $(document).on('click','#requestAdd',function(){
        $("#request").append(
            "" +
            "    " +
            "    " +
            "    " +
            "    " +
            "    +requestIndex+" style='margin-right: 5px;'>+requestIndex+">" +
            "");
        requestIndex++;
    })
    $(document).on('click','#requestSub',function(){
        var num = $("#request").find('tr').length;
            if (num > 1) {
                num = num - 1;
                $("#request tr:eq("+num+")").remove();
                requestIndex--;
            }
    })
   $(document).on('click','.request-add',function(){
    var index = parseInt($(this).attr("requestIndex"))+1;
    var trs = $(this).parent().parent().nextAll();
    if(trs.length > 0){
        for (var i = 0; i < trs.length; i++) {
            $(trs[i]).find("td").eq(0).children("input").eq(0).attr("name","requestJson["+(index+i+1)+"].value1");
            $(trs[i]).find("td").eq(1).children("input").eq(0).attr("name","requestJson["+(index+i+1)+"].value2");
            $(trs[i]).find("td").eq(2).children("input").eq(0).attr("name","requestJson["+(index+i+1)+"].value3");
            $(trs[i]).find("td").eq(3).children("input").eq(0).attr("name","requestJson["+(index+i+1)+"].value4");
            $(trs[i]).find("td").eq(4).children("a").eq(0).attr("requestIndex",(index+i+1));
            $(trs[i]).find("td").eq(4).children("a").eq(1).attr("requestIndex",(index+i+1));
        }
    }else{
        index = requestIndex;
    }
    $(this).parent().parent().after(
        "" +
        "    " +
        "    " +
        "    " +
        "    " +
        "    +index+" style='margin-right: 5px;'>+index+">" +
        "");
    requestIndex++;
   })
})

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1320670.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-11
下一篇 2022-06-11

发表评论

登录后才能评论

评论列表(0条)

保存