zoukankan      html  css  js  c++  java
  • 动态添加新行

     var order = 0;
            function AddLine()
            {
                if ($("#hid").val() == "NoSelected") {
                    order += 1;
                    var newRowHtml = "<tr key='Data'><td abc='left' onclick='selectRow(this,event)'>" + order + "</td><td><input type='text' name='projectName'/><input type='hidden' name='taskLevel' value='1'/></td></tr>";
                    $("#project_TB").append(newRowHtml);

                }
                else {
                    //已经选中了行,在选中行下面添加行
                    //获取选中行的序号
                    var selectedRowOrder = $("tr[class='selectedRow']").find("td[abc='left']").html();
                    var nowOrder = parseInt(selectedRowOrder) + 1;
                    var projectLevel_Parent = $("tr[class='selectedRow']").find("input[name='taskLevel']").val();
                    if (parseInt(projectLevel_Parent) > 1) {
                        var trHTML = "<tr Key='Data'><td onclick='selectRow(this,event)' abc='left'>" + nowOrder + "</td><td class='ProjectName_td' style='padding-left:" + (parseInt(projectLevel_Parent)) * 20 + "px'><input type='text' name='projectName'/><input type='hidden' name='taskLevel' value='" + (parseInt(projectLevel_Parent)) + "'/></td></tr>";
                        $(trHTML).insertAfter($("tr[class='selectedRow']"));
                    }
                    else {
                        var newRowHtml = "<tr key='Data'><td abc='left' onclick='selectRow(this,event)'>" + nowOrder + "</td><td><input type='text' name='projectName'/><input type='hidden' name='taskLevel' value='1'/></td></tr>";
                        //把错误的序号改成正确的
                        $(newRowHtml).insertAfter($("tr[class='selectedRow']"));
                    }
                    //获取选中行的索引
                    var selectedIndex = ($("tr[class='selectedRow']").index());
                    //错误行的索引
                    var errorIndex = parseInt(selectedIndex) + 2;
                    //获取表格有多少行
                    var rowCount = $("#project_TB tr").length;
                    for (var i = errorIndex; i < rowCount; i++) {
                        $($("#project_TB tr")[i]).find("td[abc='left']").html(i);
                    }
                }
            }

  • 相关阅读:
    MYSQL数据类型——字符串类型
    MYSQL——记录长度
    MYSQL数据类型——时间日期类型
    MYSQL数据类型——数值类型
    为什么在 IDEA jsp 中直接使用 out.println 会出错
    花指令行为大赏
    EasyCpp 题解
    [SUCTF2019] hardcpp 题解
    洛谷 P1650 田忌赛马题解
    Dict 协议是什么
  • 原文地址:https://www.cnblogs.com/lyq666666/p/5655171.html
Copyright © 2011-2022 走看看