jQuery Foreach:在不同的id上执行相同的功能

时间:2016-07-22 10:17:14

标签: php jquery ajax foreach dropzone.js

我正在使用dropzone.js和foreach图像掉入其中我应该执行相同的功能“成功”处理程序。特别是foreach图像我应该能够插入titledescription。我有类似的东西

enter image description here

我可以按照以下方式处理成功事件:

myDropzone.on("success", function(file, response) {
        //Here I get the response with the image id
        file.serverId = response;

        //Then I display the successful icon
        file.thumbnail = "<?php echo bloginfo('template_url') ?>/images/file_icon.png";

        //I can store the image id returned
        var id = file.serverId;

        //here my problem start. I've thought to assign the id to the relative image fields "title" and "description"
        jQuery( "#itemtitle" ).prop( "id","itemtitle-"+id);
        jQuery( "#itemdescription" ).prop( "id","itemdescription-"+id );

        //as screenshot displays, I should use the button "update informations" and update the relative metas
        jQuery( "#updateinformations" ).prop( "id","updateinformations-"+id );
        var updateinfo = $('#updateinformations-'+id);

        //on click I should perform this function for each image (ids)
        updateinfo.on("click", function() {
            var itemtitle = $('#itemtitle-'+id).val();
            var itemdescription = $('#itemdescription-'+id).val();

            //In fact here I'm trying to send all the infos to my AJAX action
            update_info(id, itemtitle, itemdescription);
        });
    });

我现在的问题是代码上传信息,但是,例如,如果我放置2张图片,第二张获得第一张图片的标题,依此类推。 我怎样才能在图像前分配正确的信息?

0 个答案:

没有答案