2012-06-28 49 views
1

此代碼調用新數據並將其放入div中,但不會替換舊的htm。它只是增加了它。代碼中有錯誤,但我找不到它們。我怎樣才能取代htm文件而不僅僅是添加到數據中?jQuery .active HTML顯示

.click(function() { 

    $('.tabActive').removeClass('tabActive'); 
    $(this).addClass('tabActive'); 
    var lesson = $(this).attr('.lesson'); 
    var self = this 
    $("#loading").show(); 

    setTimeout(function() { 

    $.ajax({ 
     type: "GET", 
     url: 'lessons/' + lesson + '.htm', 
     datatype: "html", 
     success: function (data) { 
     $('#sectionTabContent').append(data); 
     }, 
     complete: function() { 
     $("#loading").hide(); 
     } 
    }) 
    }, 3000); 
}); 
} 

HTML

<div id='sectionThreeTabs'>       
    <div id='' class='sectionThreeTab tabActive' lesson='first'> 
     Try 
    </div> 
    <div class='sectionThreeTab' lesson='second'> 
     Anger 
    </div> 
    <div class='sectionThreeTab' lesson='third'> 
     Size 
    </div> 
</div> 

回答

2

變化

$('#sectionTabContent').append(data); 

$('#sectionTabContent').html(data); 
0

更改的行

$('#sectionTabContent').append(data); 

$('#sectionTabContent').html(data);