2013-01-21 159 views
0

我使用ajax上传图像。使用ajax重新加载图像jquery

我想让这个函数与类名而不是id一起使用。

$(document).ready(function(){ 

var button = $('#uploader'), interval; 

new AjaxUpload(button, { 
    action: 'upload.php', 
    onSubmit : function(file , ext){ 
    if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
     alert('Error: Only images are allowed'); 
     return false; 
    } else { 
        // Image Accepted. 
    } 
    }, 
    onComplete: function(file, response){ 
     button.attr("src", response); 
    } 
}); 



}); 
在HTML

<img id="uploader" src="" /> 

工作正常,但我想添加更多的img标签。

请建议我怎样才能改变这个函数类,而不是IDS

<img class="uploader" src="" /> 
<img class="uploader" src="" /> 

回答

0

你可以阅读有关jQuery的类seletor here工作。 我想你会使用jQuery .each来循环所有的按钮或不是。

+0

IMG标签是动态创建 –

0

试试这个:

var button = $('.uploader'), interval; 

和:

<img class="uploader" src="" /> 
<img class="uploader" src="" /> 
+0

我做过尝试,但如果可能的话它不工作 –

+0

,我想使这个作为一个功能我会通过传递classname来调用它。 –

+0

任何其他建议plz –