【发布时间】:2013-01-04 13:17:04
【问题描述】:
我正在使用 ajax 上传图片。
我想让这个函数使用类名而不是 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="" />
【问题讨论】:
标签: jquery html ajax image-upload