简体   繁体   English

插件不适用于Ajax加载的内容

[英]Plugin not working on ajax loaded content

I'm using blueimp's file uploader which requires the following to be called: 我正在使用blueimp的文件上传器 ,要求调用以下文件

$('#fileupload').fileupload();

I have some ajax loaded content that contains #fileupload , but the file uploader plugin doesn't work. 我已经加载了一些包含#fileupload ajax内容,但是文件上载器插件不起作用。 How can I change the above snippet to work for ajax loaded content? 如何更改上面的代码段以适用于Ajax加载的内容?

Thanks! 谢谢!

加载ajax内容后,只需再次调用文件上传功能:

$('#fileupload').fileupload();

You have to bind the newly created elements, to not have duplicated options put them in a var: 您必须绑定新创建的元素,以确保没有重复的选项将它们放在var中:

var fileupload_options = {
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        }
    };

then just call each time a new element is created: 然后在每次创建新元素时调用:

$('#fileupload').fileupload(fileupload_options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM