javascript - 使用 javascript 添加 html 元素会使其他 js 变得不稳定

标签 javascript progress-bar swfupload

我有以下javascript代码,该代码是根据SWFUpload中的SimpleUpload演示修改的。它用于生成临时上传进度条。它工作正常,除非我添加已注释掉的代码。基本上,这一行会破坏演示文稿:

this.fileProgressElement.appendChild(document.createTextNode("Upload Status"));

演示:尝试上传。上传功能不起作用。
http://www.mgxvideo.com/mgxcopy-dev/uploader-works/upload_files.php
http://www.mgxvideo.com/mgxcopy-dev/uploader-broken/upload_files.php

代码是:
http://www.mgxvideo.com/mgxcopy-dev/uploader-works/js/sample1.txt
http://www.mgxvideo.com/mgxcopy-dev/uploader-broken/js/sample1.txt

function FileProgress(file, targetID) {
    this.fileProgressID = file.id;

    this.opacity = 100;
    this.height = 0;


    this.fileProgressWrapper = document.getElementById(this.fileProgressID);
    if (!this.fileProgressWrapper) {
        this.fileProgressWrapper = document.createElement("div");
        this.fileProgressWrapper.className = "progressWrapper";
        this.fileProgressWrapper.id = this.fileProgressID;

        this.fileProgressElement = document.createElement("div");
        this.fileProgressElement.className = "progressContainer";
        //this.fileProgressElement.appendChild(document.createTextNode("Upload Status"));

        var progressCancel = document.createElement("a");
        progressCancel.className = "progressCancel";
        progressCancel.href = "#";
        progressCancel.style.visibility = "hidden";
        progressCancel.appendChild(document.createTextNode(" "));

        var progressText = document.createElement("div");
        progressText.className = "progressName";
        progressText.appendChild(document.createTextNode(file.name));

        var progressBar = document.createElement("div");
        progressBar.className = "progressBarInProgress";

        var progressStatus = document.createElement("div");
        progressStatus.className = "progressBarStatus";
        progressStatus.innerHTML = " ";

        var progressFull = document.createElement("div");
        progressFull.className = "progressBarFull";
        progressFull.innerHTML = " ";

        this.fileProgressElement.appendChild(progressCancel);
        this.fileProgressElement.appendChild(progressText);
        this.fileProgressElement.appendChild(progressStatus);
        this.fileProgressElement.appendChild(progressBar);
        this.fileProgressElement.appendChild(progressFull);
        this.fileProgressWrapper.appendChild(this.fileProgressElement);

        document.getElementById(targetID).appendChild(this.fileProgressWrapper);
    } else {
        this.fileProgressElement = this.fileProgressWrapper.firstChild;
        this.reset();
    }

    this.height = this.fileProgressWrapper.offsetHeight;
    this.setTimer(null);


}

最佳答案

下面的效果更好吗?

this.fileProgressElement.innerHTML="Upload Status";

关于javascript - 使用 javascript 添加 html 元素会使其他 js 变得不稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1142426/

相关文章:

php - 双引号破坏 jQuery(非常简单)

python - 使用生成器作为进度通知程序

javascript - 使用 Node.js 进行管道传输时如何跟踪写入进度?

actionscript-3 - 如何使用 Actionscript3 音频发布 SWF?

javascript - 具有多个值的 json 对象的正确结构

javascript - ES6 类中转换的函数对象字面量

html - 防止带有进度条的 Flexbox 增长

javascript - swfupload:如何在上传开始前添加post参数?

javascript - SWFUpload ASP.Net 示例站点不工作?

javascript - 堆栈中视频元素的加载之间存在明显的延迟