当用户单击“取消”按钮时,我试图阻止文件上传。为此,我正在考虑停止 iframe 内的传输。问题是能够正确编码。下面是我想要实现的代码,但是当我单击“取消”按钮时出现此错误:
Uncaught exception: [Exception.... “Not enough arguments [nslDOMHTML.Document.execCommand]” nresult: “0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)” location: “JS frame;; https://......../QandATable.php = <TOP_LEVEL> ;; line 765” data: no]
首先如何修复此错误,其次如何正确编写下面的代码,以便在单击“取消”按钮时停止 iframe 内的传输?
下面是开始上传文件的 startImageUpload() 函数。在该函数中是处理单击“取消”按钮的函数;
function startImageUpload(imageuploadform){
$(".imageCancel").click(function() {
$('.upload_target')[0].contentwindow
if ($('.upload_target')[0].contentWindow.document.execCommand)
{ // IE browsers
$('.upload_target')[0].contentWindow.document.execCommand('Stop');
}
else
{ // other browsers
$('.upload_target')[0].contentWindow.stop();
}
return stopImageUpload();
});
return true;
}
以下是包含 iframe 的表单代码:
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return startImageUpload(this);' class='imageuploadform' >" +
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
"</p><p class='imagef1_cancel' align='center'><label>" +
"<input type='button' name='imageCancel' class='imageCancel' value='Cancel' /></label></p>" +
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");