jquery 展开收缩table

亢建木
2023-12-01
function zkss(objtd, tableid) {
  
    if ($(objtd).html() == "展开更多") {
        $("#" + tableid + " .changeTr").removeAttr("style");
            $(objtd).html("收缩");
        }
        else {
        $("#" + tableid + " .changeTr").css("display", "none");
            $(objtd).html("展开更多");
        }
   
}
//排行
function get_pl(tableid) {
    $("#"+tableid).html("");
    $.ajax({
        url: "ajax/userHandler.ashx",
        data: {
            type: tableid,
            rad: Math.random()
        },
        dataType: "json",
        success: function (data) {
            if (data.success == "1") {
                var item = "";
                var isyc = 0;
                $.each(data.data, function (k, dtRow) {
                    var mc = dtRow["name"];
                    var cs = dtRow["n"];
                    if (k < 3) {
                        item = item + "<tr ><td><span class=\"label label-warning\">" + (k + 1) + "</span></td><td>" + mc + "</td><td>" + cs + "</td></tr>";
                    } else {
                        if (k >= 10) {
                            isyc = 1;
                            item = item + " <tr style=\"display: none;\" class=\"changeTr\"><td><span class=\"label label-default\">" + (k + 1) + "</span></td><td>" + mc + "</td><td>" + cs + "</td></tr><tr> ";
                        }
                       else item = item + "<tr ><td><span class=\"label label-default\">" + (k + 1) + "</span></td><td>" + mc + "</td><td>" + cs + "</td></tr>";
                    }
                });

                if (isyc == 1) {

                    item = item + "   <tr> <td colspan=\"3\" οnclick=\" zkss(this,'" + tableid + "') \"  style=\"text-align:right\">展开更多</td> </tr>";
                }
                $("#" + tableid).html(item);
            }
            else {
                alert(data.data);
            }
            //点击tr 的时候,修改背景色
            changetrbk();

        },
        error: function (msg) {
            var description = "";
            for (var i in msg) {
                var property = msg[i];
                description += i + " = " + property + "\n";
            }
          //  debugger;
            alert("提交时发生系统发生错误" + description);
        }
    });
}

 类似资料: