jQuery AjaxUpload,要点击两次按钮吗? [英] jQuery AjaxUpload, have to click button twice?
本文介绍了jQuery AjaxUpload,要点击两次按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用AjaxUpload插件与jQuery,一切工作正常的大部分,但我必须点击我的按钮两次,让它执行。我猜这是一个范围问题...或(?)仍在学习...
I am using the AjaxUpload plugin with jQuery, and everything is working fine for the most part, but I have to click my button twice to get it to execute. I'm guessing this is a scope issue... or(?) still learning...
这是我的代码:
$(".upload-button").live("click", function(event) {
event.preventDefault();
var currentId = $(this).closest("div").attr("id").replace("slide-", "");
new AjaxUpload($(this), {
action: "./php/upload.php",
name: 'userfile',
autoSubmit: true,
onSubmit: function(file , ext) {
},
onComplete: function(file, response) {
// enable upload button
// this.enable();
$("#slide-" + currentId).find(".movie-image").attr("src", baseImgPath + file);
$("#mImg" + currentId).val(file);
}
});
任何想法都非常感谢。)
Any ideas are appreciated. :)
推荐答案
如果您要创建动态按钮,则需要使用每个按钮的ID创建AjaxUpload,请尝试以下操作:
If you are creating a dynamic button, you need create a AjaxUpload using a ID for each button, try this:
// to add new button
$("#add_sector").click(function() {
var ID = [Generate a new ID];
var button = '<a href="javascript:;" id="' + ID + '" class="subir_imagen"><img src="images/icon_subir32.png"></a>';
$('#cont_img_catalogo').append(button);
//create Ajax
new AjaxUpload($('#' + ID ),{
action: 'procesar_imagen.php',
name: 'image',
onSubmit : function(file, ext){
// desabilitar el boton
this.disable();
...
},
onComplete: function(file, response){
// Habilitar boton otra vez
this.enable();
...
}
});
});
要删除按钮使用:
$('#' + ID).fadeOut("slow", function() { $('#' + ID).remove(); });
如果您使用img,则需要类
if you use img, you need the class
a, a:visited{
display: block;
float: left;
text-decoration:none;}
这篇关于jQuery AjaxUpload,要点击两次按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文