Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么这个脚本不删除父元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript 为什么这个脚本不删除父元素

Javascript 为什么这个脚本不删除父元素,javascript,jquery,html,Javascript,Jquery,Html,我不知道为什么这不起作用,而且由于我有限的jquery能力,我一直无法找到问题的根源。下面的脚本将删除所有内容,而不仅仅是父元素 我很感激能帮上忙 谢谢,莉亚 脚本: // Delete post $('a.delete').livequery("click", function(e){ if(confirm('Are you sure you want to delete this post?')==false) return false; e.p

我不知道为什么这不起作用,而且由于我有限的jquery能力,我一直无法找到问题的根源。下面的脚本将删除所有内容,而不仅仅是父元素

我很感激能帮上忙

谢谢,莉亚

脚本:

    // Delete post
    $('a.delete').livequery("click", function(e){

    if(confirm('Are you sure you want to delete this post?')==false)

    return false;

    e.preventDefault();

    var parent  = $('a.delete').parent();

    var temp    = parent.attr('id').replace('record-','');

    var main_tr = $('#'+temp).parent();

        $.ajax({

            type: 'get',

            url: 'delete.php?id='+ parent.attr('id').replace('record-',''),

            data: '',

            beforeSend: function(){

            },

            success: function(){

                parent.fadeOut(200,function(){

                    main_tr.remove();

                 });

            }

        });

    });
标记:

<span id="posting">
<div class="friends_area" id="record-23">
       <img src="temp/user_icon.gif" style="width: 50px; height: 48px; float: left;" alt="">

           <label style="float: left;" class="name">

           <b>99Points</b>

           <em>ry ewst yewsrtg eswtg</em>

           <br clear="all">

           <span style="font-weight: normal;">
           9 minutes ago
           </span>
           <a href="javascript: void(0)" id="post_id23" class="showCommentBox">Comments</a>

           </label>
                    <a style="display: none;" href="#" class="delete"> Remove</a>

                    <br clear="all">
            <div id="CommentPosted23">
                            </div>
            <div class="commentBox" id="commentBox-23" style="display: none;" align="right">
                <img src="small.png" class="CommentImg" style="float: left;" alt="" width="40">
                <label id="record-23">
                    <textarea class="commentMark" id="commentMark-23" name="commentMark" cols="60"></textarea>
                <div>Write a comment...&nbsp;</div></label>

                <br clear="all">
                <a id="SubmitComment" class="smallbutton"> Comment</a>
            </div>
       </div>
           <div class="friends_area" id="record-22">

       <img src="temp/user_icon.gif" style="width: 50px; height: 48px; float: left;" alt="">

           <label style="float: left;" class="name">

           <b>99Points</b>

           <em>hywr ywerywersywrsey ry r</em>
           <br clear="all">

           <span style="font-weight: normal;">
           9 minutes ago
           </span>
           <a href="javascript: void(0)" id="post_id22" class="showCommentBox">Comments</a>

           </label>
                    <a style="display: none;" href="#" class="delete"> Remove</a>
                    <br clear="all">
            <div id="CommentPosted22">
                            </div>
            <div class="commentBox" id="commentBox-22" style="display: none;" align="right">
                <img src="small.png" class="CommentImg" style="float: left;" alt="" width="40">

                <label id="record-22">
                    <textarea style="overflow: hidden; color: rgb(51, 51, 51);" class="commentMark" id="commentMark-22" name="commentMark" cols="60"></textarea>
                <div style="position: absolute; display: none; font-weight: 400; width: 300px; font-family: monospace; line-height: 14px; font-size: 11px; padding: 0px;">Write a comment...&nbsp;</div></label>
                <br clear="all">
                <a id="SubmitComment" class="smallbutton"> Comment</a>
            </div>
       </div>

        <div id="bottomMoreButton">
    <a id="more_10" class="more_records" href="javascript: void(0)">Older Posts</a>
    </div>
                </span>

99分
ry ewst yewsrtg eswtg

9分钟前
写评论。。。

写评论。。。
使用
$(this)
而不是类选择器:)。现在您正在删除该类的所有项

var parent  = $(this).parent();
另外,请注意不能在ajax调用中使用
$(this)
(因为它将引用ajax调用),因此(意外地?)将其存储在变量中并在其上调用
。remove()

使用
$(this)
而不是使用类选择器:)。现在您正在删除该类的所有项

var parent  = $(this).parent();

另外,请注意,您不能在ajax调用中使用
$(this)
(因为它将引用ajax调用),因此您(意外地?)正在做正确的事情,将其存储在一个变量中,并在其上调用
.remove()

您能将此代码放入JSFIDLE中,以便我们能够准确地诊断问题吗?我试图粘贴此代码,但无法复制您描述的行为。您能否将此代码放入JSFIDLE中,以便我们能够准确地诊断问题?我试图粘贴此代码,但无法复制您描述的行为。