gpt4 book ai didi

jquery - Chrome 文件上传错误 : on change event won't be executed twice with the same file

转载 作者:技术小花猫 更新时间:2023-10-29 11:51:24 24 4
gpt4 key购买 nike

我正在研究这个 html5 文件 uploader 插件,但它在 Google Chrome 上有一个错误,我无法理解并修复它。它在 Firefox 上运行良好。

jsfiddle link

问题是您不能从桌面上传同一个文件两次

当您第一次点击、选择并点击“确定”以从桌面上传文件时,它应该会提示一条消息,例如“.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 已经为我的机器更新了最新版本,而这个更新导致了这个错误?

最佳答案

如果要上传两次,清空文件输入值

$('input[type="file"]').val(null);

jsfiddle test

关于jquery - Chrome 文件上传错误 : on change event won't be executed twice with the same file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com