Javascript 管理多个评论框';设置';在单页上-区分它们并正确处理

Javascript 管理多个评论框';设置';在单页上-区分它们并正确处理,javascript,jquery,html,comments,this,Javascript,Jquery,Html,Comments,This,我在同一页上有多个内容的评论框,我很难识别它们以正确对待它们-例如,我尝试在哪里发布我的评论(从哪个评论框)-它总是被发布到页面上的第一个评论框中,或者在我发布评论后,我正在与输入进行斗争以获得清除,但输入仅在同一个第一个评论框中清除。以下是我所拥有的: (阿贾克斯) (HTML) 不行!也许它没有“看到”这个属性。但为什么?!所以以下是我的猜测: $(this).parent('.post_comment').siblings('.wrap_comment').find('#show').a

我在同一页上有多个内容的评论框,我很难识别它们以正确对待它们-例如,我尝试在哪里发布我的评论(从哪个评论框)-它总是被发布到页面上的第一个评论框中,或者在我发布评论后,我正在与输入进行斗争以获得清除,但输入仅在同一个第一个评论框中清除。以下是我所拥有的: (阿贾克斯)

(HTML)

不行!也许它没有“看到”这个属性。但为什么?!所以以下是我的猜测:

 $(this).parent('.post_comment').siblings('.wrap_comment').find('#show').after(data);
(这是评论帖子,这是我对输入清除的猜测:)

我发现了类似于:

$('注释').removeAttr('值')

它不起作用-我不是说当这些东西不起作用时我会感到完全的困惑:

$(this).find('.comment').css('background-color','red');

哇。所以,我希望有人能帮我澄清一下这一切。我是一个诚实的新手。塔克斯

使用下面的脚本并用此代码替换相关脚本。我没有在您的div中找到class=“com”的多个注释框,因此我假设它只存在于该div中,而不存在于其他任何地方:

$(function() {
        $(".com").click(function() {

            //##############################$(this) here refers to div with class="com" as this is the element on which click event has happened#####################
            var myThis = $(this);
            //var parentDiv = $(this).parent('.post_comment').next().children(":first");  

            //since div with class="post_comment" is inside div with class="com" so it is child to that div and not parent
            var parentDiv = $(this).find('.post_comment').next().children(":first"); 

            //var comment = $(this).parent('.post_comment').find('.comment').val();
            var comment = $(this).find('.post_comment .comment').val();//find element with class="comment" whose parent is div with class="post_comment"

            var name = document.getElementById("username").value;

            //var idv = $(this).parent('.post_comment').find("#idv").val();
            var idv = $(this).find(".post_comment #idv").val();//find element with id="idv" whose parent is div with class="post_comment"

            //####Not sure what is the use of below statement
            var posthere = $(this).find('.wrap_comment #wrap').prop('class');

            alert(idv);
            if (comment == '')
            {
                alert("Enter some text..");
                $("#content").focus();
            }
            else
            {
                $.ajax({
                    type: "POST",
                    url: "river_flow.php",
                    data: {username: $("#username").val(),
                                idv: idv,
                                comment: comment 
                    },
                    cache: false,
                    success: function (data) {
                        $('#show').after(data);
                        //### $(this) here will not point to your div with class="com" as it is in different context inside your ajax success function
                        //##$(this).find('.comment').css('background-color', 'red');
                        myThis.find('.comment').css('background-color', 'red');

                        $("#content").focus();
                    }
                });
                return false;
            }
        });
    });

好啊你能给我链接吗?谢谢让我看看我能做些什么来帮助你!请帮我解决这个问题。我找不到你到底有什么问题,这是你的jquery代码中的某一行吗?
 $(this).parent('.post_comment').siblings('.wrap_comment').find('#show').after(data);
$(this).parent('.post_comment').find('#comment').val('');
$(this).find('.comment').css('background-color','red');
$(function() {
        $(".com").click(function() {

            //##############################$(this) here refers to div with class="com" as this is the element on which click event has happened#####################
            var myThis = $(this);
            //var parentDiv = $(this).parent('.post_comment').next().children(":first");  

            //since div with class="post_comment" is inside div with class="com" so it is child to that div and not parent
            var parentDiv = $(this).find('.post_comment').next().children(":first"); 

            //var comment = $(this).parent('.post_comment').find('.comment').val();
            var comment = $(this).find('.post_comment .comment').val();//find element with class="comment" whose parent is div with class="post_comment"

            var name = document.getElementById("username").value;

            //var idv = $(this).parent('.post_comment').find("#idv").val();
            var idv = $(this).find(".post_comment #idv").val();//find element with id="idv" whose parent is div with class="post_comment"

            //####Not sure what is the use of below statement
            var posthere = $(this).find('.wrap_comment #wrap').prop('class');

            alert(idv);
            if (comment == '')
            {
                alert("Enter some text..");
                $("#content").focus();
            }
            else
            {
                $.ajax({
                    type: "POST",
                    url: "river_flow.php",
                    data: {username: $("#username").val(),
                                idv: idv,
                                comment: comment 
                    },
                    cache: false,
                    success: function (data) {
                        $('#show').after(data);
                        //### $(this) here will not point to your div with class="com" as it is in different context inside your ajax success function
                        //##$(this).find('.comment').css('background-color', 'red');
                        myThis.find('.comment').css('background-color', 'red');

                        $("#content").focus();
                    }
                });
                return false;
            }
        });
    });