0

AJAXを介してロードされるチェックボックスで次のようなことをしたいと思います。

$('input:checkbox').each(function() {
        $(this).hide();
        alert("hi");
        $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
    });

ドキュメントの読み込み時にチェックボックスがまだ読み込まれていないため、関数は実装されません。新しくロードされたチェックボックスをループするにはどうすればよいですか?

ありがとう!

4

2 に答える 2

3

チェックボックスがのようなものを使用してロードされると仮定すると、$.ajaxメソッドsuccessは、ドキュメントに追加された後に結果のHTMLを処理する場所になります。

$.ajax({
 // your ajax options here
 success: function(html) {
    $(html).find('input:checkbox').each(function() {
        $(this).hide();
        alert("hi");
        $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
    }).appendTo(document.body); // takes the HTML from the ajax call and processes each checkbox. when done, the results are then appended to the document
 }
});
于 2012-05-16T11:49:31.813 に答える
0
    $.ajax({
    url: '/YourUrl', type: 'Get', dataType: 'json',
    // data: { id:'' },
     success: function(html) {
        $(html).find('input:checkbox').each(function() {
    if($(this).next('div.checkbox-fx').length===0)
    {
            $(this).hide();      
            $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
}
        }).appendTo(document.body);

     }
    });
于 2012-05-16T11:59:20.200 に答える