【问题标题】:reload image using ajax jquery使用ajax jquery重新加载图像
【发布时间】: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


    【解决方案1】:

    您可以阅读有关 jQuery 类选择器here 的信息。 我猜你会使用 jQuery .each 来循环所有按钮或不循环。

    【讨论】:

    • 正在动态创建img标签
    【解决方案2】:

    试试这个:

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

    还有:

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

    【讨论】:

    • 如果可能的话,我想把它作为一个函数,我会通过传递类名来调用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    相关资源
    最近更新 更多