开发者

Jquery: how to call the function again?

I'm making the script for easy upload many files. I've tried fyneworks plugin, but the file name does not appear in a form that uses tiny_mce. This is the code:

$("document").ready(function () {
    var i = 0; //iteration for Inputted File
    var max = 5; //max file uploaded
    createStatus(); //generate status container
    $('.imageNow').change(function() {
        if($(this).val()) {
            var ext = $(this).val().split('.').pop().toLowerCase();
            var allow = [ 'gif', 'png', 'jpg', 'jpeg' ];
            if (jQuery.inArray(ext, allow) != -1) { //validation true
                addImgInput($(this).clone());
                $(this).addClass('imgOK');
                $(this).removeClass('imageNow');
                addImgList($(this).val());
                removeImgStatus();
                i++;
            }
            else {
                addImgStatus();
                $(this).remove();
                addImgInput();
            }
        }
        return false;
    });
});

This is another function that I use:

function addImgInput(inputClone) {
    $(inputClone).prependTo( $开发者_如何转开发('#upload_images') ); //div container for generated InputFileImg
};

function addImgList(listingImg) {
    $('#list_image_file').append('<li>' + listingImg + '</li>' ); //list all images that have been inputted
}
function createStatus() {
    $('#upload_images').append('<small class="status"></small>'); //error display container
}
function addImgStatus() {
    $('.status').append('* Wrong File Extension'); //error display text
}
function removeImgStatus() {
    $('.status').empty();
}

Mmm..yeah is't not finished yet, because when I try to generate another Inputfile with imageNow class, the $('.imageNow').change(function() is not going to work anymore. Does anyone can help me? Thanks


i didn't actually understand if this is your problem:

when I try to generate another Inputfile with imageNow class, the $('.imageNow').change(function() is not going to work anymore.

but to solve this one you have to use .live:

$('.imageNow').live('change', function() {
   // your code
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜