我已经定义了一些点击事件处理程序如下:
$(document).ready(function () {
/*
* Since the "Start Upload" button is available, we don't need to worry about starting the
* upload when the user clicks "Update". But we need to make sure to display an error message
* if there are files in the uploader that have not been uploaded yet.
*/
$('#myAccount p.buttons input[alt="Update"]').click(function (event) {
// check if there are files in the uploader
if (uploader.files.length > 0) {
// if there are files that have not been uploaded yet, we need to show an error message
if (uploader.total.uploaded != uploader.files.length) {
// if the error message hasn't been created yet, create it
// else, it'll already be visible so we don't need to do anything
if ($('#upload_error').length == 0) {
$('<p id="upload_error">Error!</p>').insertAfter('#myAccount p.buttons input[alt="Cancel"]');
}
event.preventDefault(); // stop the click event
}
}
// continue click event as normal
});
});
... 和 ...
// if the cancel button is clicked, then remove the files from the uploader
$('#myAccount p.buttons input[alt="Cancel"]').click(function (event) {
uploader.splice(0, uploader.files.length);
// continue click event as normal
});
两者都可以在 Firefox 中正常工作,但在 IE8 和 IE7(兼容模式)中,它们并非一直都有效。
更具体地说,这个“上传器”的东西与Plupload 文件上传器有关。本质上,我在表单中有这个上传器。如果我根本不触摸上传器,则表单可以正常提交,并且上述点击处理程序可以正常工作。
但是,在以下情况下,上述点击处理程序不起作用:我将文件排队并让上传者做它的事情,所以所有文件都已上传;现在我点击表单上的提交,没有任何反应,但我希望表单能够提交。每当我与上传者交互时,点击事件处理程序都不起作用。
我希望我的评论能澄清我的意图。关于为什么这在 IE 7/8 中不起作用的任何想法?我究竟做错了什么?event.preventDefault()
IE中的处理方式不同吗?
谢谢。