开发者

Jquery live() click is making multiple instances of uploadify, how can I stop it from doing it

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜