附加数据加载问题

时间:2009-09-09 14:03:52

标签: javascript jquery html

我的HTML就像这样

<div id="rsContainer">
        <table id="rsTable"><!-- DATA HERE --></table>
</div>

我的javascript就像这样

$('#UpdateAll').click(function() {

        $('#status').fadeIn('500').text('Loading... This may take a while.');
        $.ajax({
        type: 'post',
        url: 'func.php',
        data: 'action=updateAll',

        success: function(response) {
            $('#response').fadeOut('500').fadeIn('500').append(response);

            $('#rsTable').slideUp('1000').load('index.php #rsTable', function() {
                $(this).appendTo('#rsContainer').slideDown('1000');
            });

            $('#status').fadeOut('500').empty();
        }
        });     
    });

这很好用,但在上传之后,html看起来像这样

<div id="rsContainer">
        <table id="rsTable">
            <table id="rsTable"><!--data--></table>
        </table>
</div>

正如您所看到的,它实际上将其附加到 rsTable 如何维护原始结构?

谢谢。

2 个答案:

答案 0 :(得分:1)

在我运行的测试中,在.prepend()之前执行.emtpy()比执行.html()在200次迭代中快20%。奇怪但真实。

如果你的意图是同时拥有两个rsTable,你应该在id中添加一个计数器或者使用一个类,因为id必须是唯一的。

看起来你想这样做:

$('#rsContainer').empty();
$('#rsContainer').prepend($('#rsTable'));

答案 1 :(得分:0)

$('#rsContainer').slideUp('1000').load('index.php #rsTable', function() {
    $(this).slideDown('1000');
});

将slideUp id更改为父ID。

相关问题