我正在开发一个HTML5文件上传插件,但是在Google Chrome上有一个bug,我无法理解和修复它。 在Firefox上运行良好。
问题是你无法从桌面上传相同的文件两次。
当你第一次点击选择并点击“确定”从桌面上传一个文件时,它应该弹出一个消息,例如'.button-1' - 取决于你点击的上传按钮。
然后,如果你尝试再次上传相同的文件,这行代码将不再执行:
$(".upload-file",object_parent).change(function() {
...
...
alert($cm.selector);
});
这个插件出了什么问题?
(function($){
// Attach this new method to jQuery
$.fn.extend({
// This is where you write your plugin's name
upload_file_html5: function(options) {
// Set the default values, use comma to separate the settings, example:
var defaults = {
objectSuperparent: '.media'
}
var options = $.extend(defaults, options);
var o = options;
var $cm = this.click(function(e){
// <a> button is the object in this case.
var object = $(this);
// Get other info from the element belong to this object group.
var object_href = object.attr('href');
var object_parent = object.parent();
alert($cm.selector);
// Trigger the click event on the element.
// Due to security policies triggering click on the input type=file is not allowed/supported in some browsers and Opera is one of them.
//$('input[type=file]').trigger('click'); // or:
$(".upload-file",object_parent).click();
return false;
});
// Trigger ajax post when ever the file is changed by the user.
var $cm_2 = $(".upload-file").change(function(){
// <input> is the object in this case.
var object = $(this);
var object_form = object.parent();
var object_superparent = object.parents(o.objectSuperparent);
var path_config = $($cm.selector,object_superparent).attr('href');
var path_post = object_form.attr('action');
alert($cm.selector);
//alert(path_config);
....
....
});
}
});
})(jQuery);
在Chrome上它之前运行正常,但是最近突然就不行了,可能是Chrome已经向我的电脑更新了最新版本,这个更新导致了这个bug吗?