douou1872 2015-12-23 18:51
浏览 54

如何删除“追加元素”?

I am appending a span with onclick. I cant change this because I am getting an HTML via PHP from another website.

So, I am adding in a table some informations like this:

            function getdados(id) {
              $('#loader').fadeIn();
              $.ajax({
                type: "GET",
                url: 'index.php',
                data: { action: 'getdados', id: id },
                success: function(response) {
                    if(count > 1) {
                        $('.remove').remove();
                        console.log(count);
                    }
                    response = response.replace(/\+/g, '%20');
                    var str = response.split("%");
                    var cval = str[0];
                    for (var i = 1; i < str.length; i++) {
                        cval += String.fromCharCode(parseInt(str[i].substring(0,2),16))+str[i].substring(2);
                    }
                    jQuery.event.trigger("ajaxStop");

                    $('.resultados').append(cval);

                    var titles = $(".title").map(function() { return $(this).text(); }).get(),
                        dados  = $(".dados").map(function() { return $(this).text(); }).get(),
                        header = $(".headertitle").map(function() { return $(this).text(); }).get();

                    for(var i = 0; i < dados.length; i++) {
                        switch(titles[i]) {
                            case 'Naturesa: ':
                                titles[i] = 'Natureza: ';
                                dados[i] = dados[i] + ' - ' + dados[i+1];
                                dados.splice(i+1, 1);
                                titles.splice(i+1, 1);
                                break;
                            case 'DOC: : ':
                                titles[i] = 'DOC: ';
                                break;
                            case 'Atividade primária: ':
                                dados[i] = dados[i] + ' - ' + dados[i+1];
                                dados.splice(i+1, 1);
                                titles.splice(i+1, 1);
                                break;
                            case 'Atividade secundária: ':
                                dados[i] = dados[i] + ' - ' + dados[i+1];
                                dados.splice(i+1, 1);
                                titles.splice(i+1, 1);
                                break;
                        }
                        $('#results-2 table').append('<tr class="remove"><th>'+ titles[i] +'</th><td>'+ dados[i] +'</td></tr>');
                    }

                    for(var i = 0; i < header.length; i++) {
                        var link = $('.headertitle').eq(i).nextUntil('.headertitle').map(function() {
                            if(this.localName == 'span')
                                return '<tr class="remove"><td colspan="2">'+this.outerHTML+'</td></tr>';
                        }).get().join('');
                        $('#results-2 table').append('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>'+link);
                    }

                    $('#loader').fadeOut();
                },
                error : function(transport) {
                    jQuery.event.trigger("ajaxStop");
                }
            });
        }

I need to remove all tr class="remove" from the table, but I think it is not possible :(

Someone can help me?

  • 写回答

2条回答 默认 最新

  • duanpi7107 2015-12-23 18:56
    关注

    Replace the following code:

    $('#results-2 table').append('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>'+link);
    

    With this way, which has a handle to it:

    var $tr = $('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>' + link);
    $tr.appendTo('#results-2 table');
    

    Keeping the $tr, you can reuse using:

    $tr.remove();
    

    Or, the old school way, you can find the .remove:

    $("tr.remove").remove();
    

    If I don't understand your question, may be you just need to remove the class remove from the elements, use:

    $("tr.remove").removeClass("remove");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题