【问题标题】:keep old status with jquery使用 jquery 保持旧状态
【发布时间】:2013-01-10 14:08:45
【问题描述】:

我从这里下载了1个上传进度条:http://www.malsup.com/jquery/form/progress3.html

完美;无论如何,当文件被上传时,它会给出一个关于文件的状态,比如:

文件上传到http://mysite.com/1.jpg

但是,当上传新文件时,状态会消失,并会出现有关刚刚上传的新文件的详细信息。

我只想拥有旧状态,当上传新文件时,新状态会出现在旧状态下。我怎么能这样做?

代码如下:

(function() {

var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
    status.empty();
    var percentVal = '0%';
    bar.width(percentVal)
    percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
    var percentVal = percentComplete + '%';
    bar.width(percentVal)
    percent.html(percentVal);
    //console.log(percentVal, position, total);
},
complete: function(xhr) {
    status.html(xhr.responseText);
}
}); 

})();       
</script>

如果您在链接中看到demo 并很好理解,则该状态会出现在 HTML 中,如下所示:

 <div id="status"></div>

谢谢!

【问题讨论】:

    标签: php javascript jquery jqxhr


    【解决方案1】:

    您的complete 回调正在重置status.html(),并且您的beforeSend 正在用status.empty(); 清空status。删除该行!

    然后尝试prepending 包裹在一些标记中的最新消息,而不是覆盖status 的全部内容:

    complete: function(xhr) {
        var message = '<div class="new">' + xhr.responseText + '</div>';
        status.prepend(message);
    }
    

    【讨论】:

    • sry 但我知道 jquery im php 程序员你能举个例子吗?
    • status.html(status.html() + xhr.responseText);(但这取决于你的html结构)
    • 不工作 status.html(status.html() + xhr.responseText); }
    • 抱歉,我误解了 jQuery 的 wrap 方法的功能。我用一种方法更新了我的答案,在手动构造的 html 字符串之前添加了 xhr.responseText
    • 我刚刚注意到您还在 beforeSend 函数中清空了 status。重新阅读我更新的答案。
    猜你喜欢
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    相关资源
    最近更新 更多