我有一个包含文件输入、上传按钮和取消按钮的表单:
<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='stopImageUpload(this);' class='imageuploadform' >
<p class='imagef1_upload_form' align='center'><label>Image File: <input name='fileImage' type='file' class='fileImage' /></label>
<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>
我已经设置了 php 来上传文件和所有这些,并且上传工作完美。由于下面的 javascript 函数,上传开始和停止,但我的问题是如何对其进行编码,以便当用户开始上传(startImageUpload() 函数)时,如果用户希望在上传期间通过单击取消上传取消按钮,然后它停止上传(我相信它需要导航到 stopImageUpload() 函数,但我不确定这是否正确)。
我已将所有内容设置为正确显示在屏幕上,我只需要知道能够成功取消上传以及显示已在 stopImageUpload 中的消息“上传期间出错”的正确功能是什么() 功能。
下面是开始上传的函数:
function startImageUpload(imageuploadform){
$(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
$(imageuploadform).find('.imagef1_cancel').css('visibility','visible');
$(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
sourceImageForm = imageuploadform;
return true;
}
以下是上传完成的函数:
function stopImageUpload(success){
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
$(sourceImageForm).find('.imagef1_upload_process').css('visibility','hidden');
$(sourceImageForm).find('.imagef1_cancel').css('visibility','hidden');
return true;
}