2013-01-21 161 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 –