0

所以我最近遇到了一个问题,当我尝试在 Firefox 中上传文件时,它会被重置。我已经在 Chrome 中测试了这个功能,它运行良好,但它在 Firefox 中不起作用。查看萤火虫控制台日志没有让我知道它在哪里重置。我正在使用resumable.js JS 库通过 PHP 后端对我的上传进行分块。这在 Chrome 中 100% 有效。

当我单击调用该resume.upload()方法的上传按钮时会发生这种情况,并且一旦这样做,它就会重置框架,因此上传不会通过。如果我在调用这个方法的地方添加一个断点,并让它执行一次,它工作正常,但如果我放开它,它只是重置

JS和HTML的小片段:

<form>
<input id="showBrowse" style="margin-right:5px;" type="file">&nbsp;&nbsp;&nbsp;
<button id="uploadFileBTN" style="margin-left:25px" onclick='resume.upload()'>Start Upload</button>&nbsp;&nbsp;&nbsp;
<br>
<span style="margin-right:3px;margin-right:10px;" id="pauseOrplay"></span><img id='pauseDL' onclick='resume.pause();paused();' alt="Pause">
<span style="margin-left:23px;margin-right:10px;" id="cancelTXT"></span><img id='cancelDL' onclick='resume.cancel();cancel();' alt="Cancel">
<br>
<input type="checkbox" id="overwriteFile" onclick='overwriteIt()'>Overwrite if file already exists <br>
<input type="hidden" value="<%=view.getUID()%>" id="hiddenUID">
</form>

这是JS实现

/**
 * Resumable.js implementation
 */
$("#stitchLabel").hide();
resume = new Resumable({
    target:uploadURL,
    query:{rewrite: $("#overwriteFile").attr('checked')?true:false},
    resumableChunkSize:1*1024*1024,
    simultaneousUploads:1,
    testChunks:false
});
if(!resume.support){
    hidePauseAndCancel();
    $("#showBrowse").hide();
    $("#uploadFileBTN").hide();
    alert("Sorry! The upload file feature is not supported on your browser. Please use Firefox 4+, Chrome 11+, or Safari 6+");
}
resume.assignBrowse(document.getElementById("showBrowse"));

resume.on('fileAdded',function(file){
    var idFile = file.uniqueIdentifier;
    $("#fileBlock").append("<li id='"+file.uniqueIdentifier+"'>"+file.fileName+"&nbsp;&nbsp;&nbsp;<span id='fileProgress'><b>Waiting for upload to start</b></span></li>");
    $("#uploadFileBTN").attr('disabled',false);
    $("#overwriteFile").attr('disabled',true);
    $("#pauseDL").hide();
    $("#resumeDL").hide();
    $("#pauseOrplay").hide();

});

resume.on('fileSuccess',function(file, message){
    alert("finished");
    var name = file.fileName;
    $("#fileBlock").find("#"+file.uniqueIdentifier).remove();
    $("#userFiles").children().find("img#pauseDL").remove();
    $("#userFiles").children().find("img#resumeDL").remove();
    $("#fileBlock").children().find("#"+file.uniqueIdentifier).css('color',"#D4D4D4");
    $("#fileBlock").find("#wait").show();
    hidePauseAndCancel();
    if(($("#fileBlock").find("#wait")).length == 0){
        $("#fileBlock").append("<b id='wait'>Stitching... don't press cancel</b>");
    }

});
resume.on('fileProgress', function(file){
    if(resume.progress()*100>0){
        $("#pauseDL").attr('src','/img/IMGS/icons/pause.png').show();
        $("#pauseOrplay").html("<b>Pause</b>&nbsp;&nbsp;&nbsp;");
        $("#pauseOrplay").show();
        $("#cancelTXT").html("<b>Cancel</b>");
    }
    $("#cancelDL").attr('src','/img/IMGS/icons/delete-icon.png').show();
    $("#cancelTXT").html("<b>Cancel</b>");
    $("#cancelTXT").show();
    $("#uploadFileBTN").attr('disabled',true);
    $("#fileBlock").find("#"+file.uniqueIdentifier).find("#fileProgress").html("&nbsp;&nbsp;&nbsp;<b>"+Math.floor(file.progress()*100)+"%</b>").css('color','#05AD24');
    $("#overwriteFile").attr('disabled',true);
});

Firebug 根本不提供任何消息。FF 不支持我正在使用的东西吗?顺便说一句,FF v20。

4

1 回答 1

0

好吧,好像firefox不喜欢

<button></button>

并且喜欢

<input type="button">

一旦我改变了它,onclick 事件就会正常触发。

于 2013-04-10T19:29:06.053 回答