0

すべてのdivブロックは同じクラス名を使用しており、ファイルのアップロードが完了した後に新しいdivブロックを追加する必要があります。私のやり方では、既存のすべてのブロックに新しいブロックが追加されます。これが私のテストコードです:

HTML:

<div class="img_container" id="img1">EXISTING BLOCK</div>'
<div class="img_container" id="img2">EXISTING BLOCK</div>'

JQuery:

$('#fileupload').bind('fileuploadcompleted', function (e, data) {
    e.preventDefault();
    var $newdiv = $('<div class="img_container" id="img3">NEW BLOCK</div>');

    $('.img_container').append($newdiv);
})

bodyタグに追加しようとしましたが、新しいdivが表示されません。どうすればこれを解決できるのでしょうか?

4

1 に答える 1

5
$('.img_container:last').after($newdiv) // should do the trick
于 2012-07-03T13:18:24.433 に答える