Uploadify with live click and toggle is creating multiple instances of the upload button how can I stop it from doing that.
My code:
// Display sub comments Fo开发者_运维知识库rm
$(document).find("div[id^='subreply-']").live('click', function(){
var num = this.id.split('-')[1];
$('#subboxes-' + num).toggle();
$('#file_upload1-' + num).uploadify({
'uploader' : 'js/uploadify.swf',
'script' : 'js/uploadify.php',
'cancelImg' : 'js/cancel.png',
'folder' : 'upload',
'auto' : true,
'multi' : false,
'onComplete' : function(event, queueID, fileObj, response, data) {
$("#commentfile-" + num).val(fileObj.name);
}
});
});
What am I doing wrong?
Thanks
How about this quick fix?
var uploadify_instances = {};
$(document).find("div[id^='subreply-']").live('click', function(){
var num = this.id.split('-')[1];
if(!uploadify_instances['#file_upload1-' + num]) {
uploadify_instances['#file_upload1-' + num] = true;
$('#subboxes-' + num).toggle();
$('#file_upload1-' + num).uploadify({
'uploader' : 'js/uploadify.swf',
'script' : 'js/uploadify.php',
'cancelImg' : 'js/cancel.png',
'folder' : 'upload',
'auto' : true,
'multi' : false,
'onComplete' : function(event, queueID, fileObj, response, data) {
$("#commentfile-" + num).val(fileObj.name);
}
});
}
});
Edit: yup, I've made it unnecessary complicated at first.
精彩评论