Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 删除父元素jQuery_Javascript_Jquery - Fatal编程技术网

Javascript 删除父元素jQuery

Javascript 删除父元素jQuery,javascript,jquery,Javascript,Jquery,单击时如何删除所有元素,包括其父元素。选项卡是动态生成的。到目前为止,我尝试的是: 我用bootbox来确认 function remove() { bootbox.confirm("Are you sure?", function(result) { if( result != false ) { var anchor = $(this).siblings('a'); $(anchor.attr('hr

单击时如何删除所有元素,包括其父元素。选项卡是动态生成的。到目前为止,我尝试的是:

我用bootbox来确认

function remove() {
        bootbox.confirm("Are you sure?", function(result) {
          if( result != false ) {
              var anchor = $(this).siblings('a');
              $(anchor.attr('href')).remove();
              $(this).parent().remove();
              $(".nav-tabs li").children('a').first().click();
          }
    }); 
}
我将删除的选项卡是通过以下方式生成的:

$(document).on('submit','#pop-form', function(e) {
    // make an ajax request
    $.post('../admin/FLT_add_tab.do',
            $('#pop-form').serialize(),
            function( data ) {
                // if data from the database is empty string
                if( $.trim( data ).length != 0 ) {
                    // hide popover
                    $('#popover').popover('hide');
                    //append new tab and new tab content
                    var id = $(".nav-tabs").children().length - 1;
                    $('#popover').closest('li').before('<li><a href="#tab_'+ id +'" data-toggle="tab" class="g-tabs">' + data + '&nbsp;</a></li>');         
                    $('.tab-content').append('<div class="tab-pane" id="tab_' + id + '"> <c:import url="flt-pis.html"></c:import> </div>');
                } else {
                    // error handling later here
                }
            }
    );
    e.preventDefault();
});
与页面是否刷新有关的JS

<!-- Other tabs from the database -->
<c:forEach var="tabNames" items="${ allTabs }">
    <li><a href="#tab_${ tabNames.value }" data-toggle="tab" class="g-tabs">${ tabNames.key }&nbsp;</a></li>
</c:forEach>

  • 用于添加新选项卡的弹出窗口

    <!-- Add new tab -->
    <li><a href="#" id="popover">New <i class="icon-plus-sign"></i></a></li>
    
    
    

  • 我不能确切地说出您是如何实现这一点的,但如果我的猜测是正确的,那么这应该是可行的。 如果不起作用,你应该考虑设置小提琴。

    function remove() {
         bootbox.confirm("Are you sure?", function(result) {
            if (result) { $(this).remove(); }
         });
    }
    

    我不能确切地说你是如何实现这一点的,但如果我的猜测是正确的,这应该是可行的。 如果不起作用,你应该考虑设置小提琴。

    function remove() {
         bootbox.confirm("Are you sure?", function(result) {
            if (result) { $(this).remove(); }
         });
    }
    

    主要问题是
    remove
    方法不知道在哪个元素上调用它,我已将remove更改为使用jQuery处理程序,而不是内联的click处理程序

    试一试

    $(document).on('mouseenter','a.g-tabs',function(){
    添加($('');
    });
    $(文档).on('mouseleave','a.g-tabs',函数(){
    $(this.find(“.icon clear remove:last”).remove();
    });
    jQuery(函数(){
    $(文档)。在('单击','上。清除图标以删除',函数(){
    var$this=$(this);
    bootbox.confirm(“确定吗?”),函数(结果){
    如果(结果!=错误){
    警报('delete:'+$this[0]。标记名)
    var$a=$this.closest('.g-tabs');
    警报($a.length)
    $($a.attr('href')).remove();
    $a.parent().remove();
    $(“.nav tabs li”).children('a').first().click();
    }
    });
    })
    })
    
    主要问题是
    remove
    方法不知道在哪个元素上调用它,我已将remove更改为使用jQuery处理程序,而不是内联单击处理程序

    试一试

    $(document).on('mouseenter','a.g-tabs',function(){
    添加($('');
    });
    $(文档).on('mouseleave','a.g-tabs',函数(){
    $(this.find(“.icon clear remove:last”).remove();
    });
    jQuery(函数(){
    $(文档)。在('单击','上。清除图标以删除',函数(){
    var$this=$(this);
    bootbox.confirm(“确定吗?”),函数(结果){
    如果(结果!=错误){
    警报('delete:'+$this[0]。标记名)
    var$a=$this.closest('.g-tabs');
    警报($a.length)
    $($a.attr('href')).remove();
    $a.parent().remove();
    $(“.nav tabs li”).children('a').first().click();
    }
    });
    })
    })
    

    如何调用
    remove
    你能做一把小提琴吗?这样做会更容易understand@ArunPJohny我更新了question@Hiral很抱歉,这些选项卡是从引导中创建的,我不知道如何在没有它的情况下创建选项卡。如何调用
    remove
    可以制作小提琴吗?这样做会更容易understand@ArunPJohny我更新了question@Hiral很抱歉,这些标签来自引导,我不知道如何在没有它的情况下创建选项卡。@user2785929是否显示确认消息?@user2785929我用两条警告语句更新了代码,它们显示了什么第一条是
    delete
    ,第二条是
    0
    ,并且当当前生成选项卡时,单击事件不会显示触发器第一个是
    I
    ,第二个仍然是
    0
    @user2785929是否显示确认消息?@user2785929我用两条警报语句更新了代码,它们显示了什么第一个是
    delete
    ,第二个是
    0
    ,以及当前生成选项卡时的单击事件不会触发第一个是
    I
    ,第二个仍然是
    0
    $(document).on('mouseenter', 'a.g-tabs', function () {
        $(this).append($('<i class="icon-clear-remove"></i>'));
    });
    $(document).on('mouseleave', 'a.g-tabs', function () {
        $(this).find(".icon-clear-remove:last").remove();
    });
    
    jQuery(function () {
        $(document).on('click', '.icon-clear-remove', function () {
            var $this = $(this);
            bootbox.confirm("Are you sure?", function (result) {
                if (result != false) {
                    alert('delete:' + $this[0].tagName)
                    var $a = $this.closest('.g-tabs');
                    alert($a.length)
                    $($a.attr('href')).remove();
                    $a.parent().remove();
                    $(".nav-tabs li").children('a').first().click();
                }
            });
        })
    })