Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
使用jQuery获得最接近的li_Jquery_Events_Click_Removeclass - Fatal编程技术网

使用jQuery获得最接近的li

使用jQuery获得最接近的li,jquery,events,click,removeclass,Jquery,Events,Click,Removeclass,我试着用jQuery点击并移除最接近的li按钮,但似乎没有触发 这是我的标记 <li class="dd-item dd3-item" data-id="22"> <div class="dd-handle dd3-handle"></div> <div class="dd3-content">some other <span class="pull-right" style="display: none;"&

我试着用jQuery点击并移除最接近的li按钮,但似乎没有触发

这是我的标记

<li class="dd-item dd3-item" data-id="22">
    <div class="dd-handle dd3-handle"></div>
    <div class="dd3-content">some other
        <span class="pull-right" style="display: none;">
            <a data-target="#settings_22" data-action="collapse" href="#"><i class="fa fa-pencil"></i></a>
        </span>
    </div>

    <form method="post" action="#" class="menu_settings" style="display: block;">
        <input type="hidden" value="22" name="id">
        <fieldset>

            <div role="toolbar" class="btn-toolbar">
                <div class="btn-group btn-group-sm">
                    <button type="button" data-action="update" class="update btn btn-default"><i class="fa fa-upload"></i> Update</button>
                    <button type="button" data-action="delete" class="delete btn btn-default"><i class="fa fa-trash-o"></i> Trash</button>
                    <button type="button" class="cancel btn btn-default"><i class="fa fa-times"></i> Cancel</button>    
                </div>                                
            </div>
        </fieldset>                        
    </form>
</li>

我确实收到了警报,但列表没有被删除

默认情况下,使用
引用
窗口
执行成功回调;这可能不是你想要的

您可以使用
$的
上下文
选项在成功回调中绑定
。ajax

$.ajax({
    ...,
    context: this,
    ...
});

这确保了在成功回调中使用
$(This)
将是单击的元素。

它正在工作:在这里工作-我对我的hole jquery进行了更新,显示了如何使用这里只有一个li,其中包含所有控件,您想删除此li还是有其他li(在此li旁边)要删除的。在<代码>$(this).closest('li').remove()中,
$(这个)
可能不是指你认为它指的东西。
$.ajax({
    ...,
    context: this,
    ...
});