我目前正在使用Javascript在我的网站中设置进度栏。它在Google Chrome上可以很好地工作,但是在Firefox中却不能。
function uploadFile() {
var file = document.getElementById("fileToUpload").files[0];
var formdata = new FormData();
formdata.append("fileToUpload", file);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.open("POST", "send.php");
ajax.send(formdata);
}
function progressHandler(event) {
var percent = (event.loaded / event.total) * 100;
document.getElementById("progressBar").value = Math.round(percent);
document.getElementById("status").innerHTML = Math.round(percent) + "%";
if (document.getElementById("status").innerHTML == "100%") {
document.getElementById("status").innerHTML = "Finalisation...";
}
}
function completeHandler(event) {
document.getElementById("progressBar").value = 100;
}
我希望进度条能与Firefox一起使用,但根本无法使用。