代码之家  ›  专栏  ›  技术社区  ›  montooner

使用javascript添加一个HTML元素会使其他JS变得不稳定。

  •  1
  • montooner  · 技术社区  · 15 年前

    我有下面的javascript代码,它是从swfupload中的simpleupload演示中修改的。它用于生成临时上载进度条。它工作得很好,除非我添加了注释掉的代码。基本上,这一行将打断演示:

    this.fileProgressElement.AppendChild(document.createTextNode(“上载状态”));

    演示:尝试上传。上载功能不起作用。
    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);
    
    
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Josh Andreas Rehm    15 年前

    以下工作是否更好?

    this.fileProgressElement.innerHTML="Upload Status";
    
    推荐文章