DragonWar% 2016-01-05 08:10 采纳率: 0%
浏览 31

追加并折叠子行

I want to append and collapse child row by clicking parent row, but it does not work. What should I do. Can anybody help??

This is my parent row:

$j(document).ready(function(){

$.ajax({
type: 'POST',
url:"scr1.php",

}).done(function(data){

for(var i=0; i<data.length; i++){

    var no = i+1;
    $table ="<tr class='row-parent'>";
    $table += "<td align='right'>"+no+ "</td>";
    $table += "<td  class='row-child'>"+data[i].uid+ "</td>";
    $table += "<td>"+data[i].document_id+ "</td>";
    $table += "<td>"+data[i].activity+ "</td>";
    $table += "<td>"+data[i].date_time+ "</td>";
    $table +="</tr>";

    $("#docLoc").append($table);
    }
    });
});

And this is my child row:

//child row
$(".row-parent").live("click",function(){

    var param = $(this).closest('tr').find('.row-child').text();//GET uid of row

    $.ajax({
        type: 'POST',
        url:"scr2.php",
        data:{ uid: param},
        //Link to history.php. Pass user_id to url
        }).done(function(data){

        for(var i=0; i<data.length; i++){
            alert(data[i].uid);
            var no = i+1;
            $table ="<tr>";
            $table += "<td align='right'>"+no+ "</td>";
            $table += "<td>"+data[i].uid+ "</td>";
            $table += "<td>"+data[i].document_id+ "</td>";
            $table += "<td>"+data[i].activity+ "</td>";
            $table += "<td>"+data[i].date+ "</td>";
            $table +="</tr>";

            $("#docLoc").append($table);
        }

    });
});

Did I miss out something??

Thanks in advance!!

  • 写回答

1条回答 默认 最新

  • weixin_33671935 2016-01-05 08:51
    关注

    If the object is dynamically produced, you will need to call use ".on" method on the parent (which always exists) and a ".enhanceWithin()" method on the parent after creating the child for it to respond to jQuery

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀