0

私は、いくつかのボタンを動的に生成するこの Fiddle http://jsfiddle.net/wNDaG/のコードを使用しています。ただし、私がやりたいのは、各ボタンに ajax を介して一部のコンテンツをロードする (div に追加する) 機能も実行させることです。

フィドルのコードは次のとおりです。

$('#tabs div').first().attr('class', 'current');

$('#tabs div').each(function(i) {
    i = i + 1;

$(this).attr('id', 'tab-' + i);

    if(i !== $('#tabs div').size()) {
    $(this).append('<button class="tabPagination" rel="tab-' + (i + 1) + '">Next</button>');
}
    if(i !== 1) {
    $(this).append('<button class="tabPagination" rel="tab-' + (i - 1) +    '">Previous</button>');
    }                
});            

$('#tabs div[class!="current"]').hide();

$('.tabPagination').live('click', function() {
    $('.current').removeAttr('class');
    $('#tabs div[class!="current"]').hide();
    $('#' + $(this).attr('rel')).show();
});

まず、追加したボタンに次のようなものを追加します。

href="some-content/next-pagenum_' + (i + 1) + '"

その後、ajax を介してコンテンツを追加する次のような関数を組み合わせるために助けが必要です。

$('.tabPagination').live('click', function(event) {
    var url = $(this).attr('href');
$('#content-target-div').load(url); // load the html into your chosen DOM element
    event.preventDefault(); // prevent the browser from navigating to this page  

    return false;
 });

ここで何か助けていただければ幸いです。前もって感謝します!

4

2 に答える 2

0

最も簡単な方法は、次のようにすることです。

$.get(url, function(content) {
    $('#content-target-div').append(content);
});

代わりに

$('#content-target-div').load(url);
于 2013-04-03T23:17:19.697 に答える