• 多级评论代码实现(前端篇)


    1.递归法:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .comment-box{
                margin-left: 20px;
            }
        </style>
    </head>
    <body>
        <div class="item">
            <a news_id="19" class="com">评论</a>
            
        </div>
        <div class="item">
            <a news_id="18" class="com">评论</a>
        </div>
        <div class="item">
            <a news_id="17" class="com">评论</a>
        </div>
    
    
        <script src="/static/jquery-2.1.4.min.js"></script>
        <script>
            $(function () {
                bindCommentEvent();
            });
            function bindCommentEvent() {
               $('.com').click(function () {
                   var news_id = $(this).attr('news_id');
                   var _this = $(this);
    
                   $.ajax({
                       url: '/comment/',
                       type: 'GET',
                       data: {news_id: news_id},
                       dataType: "html",
                       success:function (arg) {
                           //create_tree(arg, _this);
                           console.log(arg);
                           _this.after(arg);
                       }
                   })
    
               })
            }
    
            function diGui(children_list){
                    var html = "";
                    $.each(children_list,function (ck,cv) {
                           var b = '<div class="comment-box"><span>';
                           b+= cv.content + "</span>";
                           b += diGui(cv.children);
                           b += "</div>";
                           html += b;
                     });
                    return html;
                }
    
    
                function create_tree(data,$this) {
                     var html = '<div class="comment-list">';
                     $.each(data,function (k,v) {
                        var a = '<div class="comment-box"><span>';
                         a+= v.content + "</span>";
                         // 创建自评论
                         a += diGui(v.children);
                         a+= "</div>";
                         html += a;
                     });
    
                     html += "</div>";
                    $this.after(html);
            }
    
    
        </script>
    
    </body>
    </html>
  • 相关阅读:
    Solaris 10学习笔记初学
    EBS R12中文升级补丁
    EXPDP,今天犯了个愚蠢的错误
    LOGSTDBY status: ORA01418,Logical standby問題可真多
    ORA04045,Standby停止Apple log处理一例
    无法relay信件处理一例
    cordova启动页面和图标的设置
    CSS布局探密02
    CSS布局探密01
    CSS布局探密03
  • 原文地址:https://www.cnblogs.com/qvpenglou/p/11580894.html
Copyright © 2020-2023  润新知