JQuery动态加载Table

用于在同一Table显示两级内容
点击一次,会用ajax从服务器加载json数据,并添加到该行下面
再点击一次,会利用name属性,删除对应的行

function ExpendPatient(srow,pid){
    var imgc = "#p"+pid+"imgc";
    var imgo = "#p"+pid+"imgo";

    if($(imgo).is(":visible"))
    {
        $(imgo).hide();
        $(imgc).show();
        
        delrows = document.getElementsByName("p"+pid+"study");
        for (var i=0;i<delrows.length;i++) 
        {
            delrows&#91;i&#93;.parentNode.removeChild(delrows&#91;i&#93;);
        }
        return;
    }
    $(imgc).hide();
    $(imgo).show();
    
    aurl="xxxxxxxxxxxx?patPk="+pid;
    try
    {
        $.ajax({
          url: aurl,
          dataType: 'json',
          error: function(XMLHttpRequest, textStatus, errorThrown){
            alert('错误原因 ' + textStatus);
            alert('错误堆栈 ' + errorThrown);
            alert('返回字符 ' + XMLHttpRequest.responseText);
          },
          success: function(data) {
              $.each(data,function(i,record){
                  r = '<tr height="30" name="p'+pid+'study" onclick="DoSomeThing(this,'+record&#91;"pk"&#93;+');"&#93;';
                  r += '<td></td>';
                  r += '<td>'+record["a"]+'</td>';
                  r += '<td>'+record["b"]+'</td>';
                  r += '<td>'+record["c"]+'</td>';
                  r += '<td>'+record["d"]+'</td>';
                  r += '<td>'+record["e"]+'</td>';
                  r += '<td>'+record["f"]+'</td>';
                  r += "</tr>";
                  $(srow).after(r);
              });
          }
        });
    }
    catch(e)
    {
        alert(e);
    }
}

Comments are closed.