求jquery js大神解决操作表格问题,万分感谢

2025-05-19 00:22:19
推荐回答(1个)
回答(1):




    
    
    
        .tb_table
        {
            border-collapse: collapse;
            border: none;
            width: 100%;
        }
        .tb_table > thead > tr > th
        {
            border: 1px solid #ccc;
            height: 30px;
        }
        .tb_table > tbody > tr > td
        {
            border: 1px solid #ccc;
            height: 25px;
            width: 220px;
        }
    
    
        function Update(num) {
            $("label").each(function () {
                if ($(this).attr("data-name") == "lbl_" + num) {
                    $(this).hide();
                }
            });
            $("#id_" + num).removeAttr("hidden");
            $("#name_" + num).removeAttr("hidden");
            $("#age_" + num).removeAttr("hidden");

            $("#btn_" + num).show();
        }

        function Save(num) {
            $("label").each(function () {
                if ($(this).attr("data-name") == "lbl_" + num) {
                    $(this).show();
                }
            });
            $("#id_" + num).attr("hidden", "hidden");
            $("#" + $("#id_" + num).attr("data-lbl")).text($("#id_" + num).val());

            $("#name_" + num).attr("hidden", "hidden");
            $("#" + $("#name_" + num).attr("data-lbl")).text($("#name_" + num).val());

            $("#age_" + num).attr("hidden", "hidden");
            $("#" + $("#age_" + num).attr("data-lbl")).text($("#age_" + num).val());

            $("#btn_" + num).hide();
        }

        function Delete(num) {
            $("#tr_" + num).remove();
        }

        function AddLine() {
            var num = parseInt($("#hdfnum").val());
            num++;
            $("#hdfnum").val(num);
            var html = '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            html += '';
            $(".tb_table>tbody").append(html);

        }
    


    
    
        
            
                
                    编号
                
                
                    姓名
                
                
                    年龄
                
                
                    操作
                
            
        
        
            
                
                    
                        1
                    
                
                
                    
                        张数
                    
                
                
                    
                        21
                    
                
                
                    
                    
                
            
        
    
    

代码,测试不严谨,自己修修改改了