【问题标题】:Append text to jQuery first after progress is done进度完成后首先将文本附加到 jQuery
【发布时间】:2013-10-23 21:35:58
【问题描述】:

问题:

在进度条完成后但在 setTimeout() 启动之前将文本附加到 div。

HTML 代码:

<div id="loading" class="files"></div>

jQuery 代码:

<script>    
    $(function () {
        'use strict';
        // Server-side upload handler:
        var url = 'process.php';

        $('#fileupload').fileupload({
            url: url,
            autoUpload: true,
            acceptFileTypes: /(\.|\/)(txt)$/i,
            maxFileSize: 5000000, // 5 MB
            done: function (e, data) {
                setTimeout(function(){
                    window.location = "explorer.php";}, 2000);
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .progress-bar').css(
                    'width',
                    progress + '%'
                );
            }
        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');
    });
</script>

期望的结果:

当进度条达到 100% 后,将文本“Loading ...”附加到 div,然后启动 setTimeout()。

【问题讨论】:

    标签: javascript jquery html progress-bar settimeout


    【解决方案1】:

    done 方法应该有执行此操作的代码。所以你的完成会变成,

    progressall: function (e, data) {
                    var progress = parseInt(data.loaded / data.total * 100, 10);
                    $('#progress .progress-bar').css(
                        'width',
                        progress + '%'
                    );
                    if (progress == 100)
                        $("#loading").html("Loading...");
                }
    

    但文本“正在加载...”只会向用户显示几秒钟,因为我们在 2 秒后启动了页面刷新。

    【讨论】:

    • 尝试了这个解决方案,但文本会在进度建立时直接出现。我想知道文本和进度之间是否可能有延迟?
    • 然后我们就可以添加code in progressall函数了。我已经编辑了上面的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多