0

jQueryに問題があり、作成後にdivを削除しません...コードは次のとおりです

$('.del').on('click', function() {
        //delItem = $(this);
        var data_id = $(this).attr('rel');
        $.post('index/xhrDelete', {'data_id': data_id}, function(o) {
            //delItem.parent().remove(); // i have tried this too
            $(this).parent().remove();
        }, 'json');
        return false;
});

それはdivを削除しますが、手動で更新すると...しかし、ページを更新せずにここにあるのはhtmlです....

<div>
     ccc
     <a class="del" href="#" rel="5">X</a>
</div>
<div>
test
     <a class="del" href="#" rel="21">X</a>

テスト済み X

4

2 に答える 2

0

これを試してみてください:

$('.del').on('click', function(e) { // Notice the 'e' in the function
    $this = $(e.target); // Use it to retrieve the element that fired the event and turn it into a jQuery object
    var data_id = $(this).attr('rel');
    $.post('index/xhrDelete', {'data_id': data_id}, function(o) {
        $this.parent().remove(); // You just need to remove its parent
    }, 'json');

    return false;

});
于 2013-10-15T07:46:06.617 に答える