newajax onclick不适用于动态创建的项目

I have a table where users can add rows using jquery. This is all working fine to a point. the problem I have is the dynamically created row has a button with an onclick event that connect to new Ajax code to browse from computer. The problem is button work in first generated row but when i generated another the button not work .

This is the button with onclick event:

<a  onclick="image_upload('image<?php echo $image_row; ?>', 'thumb<?php echo $image_row; ?>');" id="simple-image<?php echo $image_row; ?>" class="upimage"><?php echo $text_browse; ?></a>

New Ajax code for event :

  function  image_upload(field, thumb ){
    new AjaxUpload('#simple-image' + <?php echo $image_row; ?>, {
    action: 'index.php?route=common/filemanager/upload&image=' + encodeURIComponent($('#' + field).attr('value')),
    name: 'image',
    autoSubmit: true,
    responseType: 'json',

    onChange: function(file, extension) {

        this.setData({'directory': ''});
     this.submit();
    },

    onSubmit: function(file, extension) {
        $('#simple-image' + <?php echo $image_row; ?>).append('<img src="catalog/view/theme/default/image/loading.gif" class="loading" style="padding-left: 5px;" />');
    },
    onComplete: function(file, json) {
        if (json.success) {
         $('#' + field).attr('value','data/user/'+file);
            $.ajax({
                    url: 'index.php?route=common/filemanager/image&image=' + encodeURIComponent($('#' + field).attr('value')),
                dataType: 'text',
                success: function(text) {
                $('#' + thumb).replaceWith('<img src="' + text + '" alt="" id="' + thumb + '" />');                          
                }
            });
        }

        if (json.error) {
            alert(json.error);
        }

        $('.loading').remove(); 
    }
     });

        };  

Any help will be much appreciated.

查看全部
dro60731
dro60731
2015/05/02 21:20
  • php
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复