简体   繁体   English

jQuery:如何再次调用该函数?

[英]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 . 我试过了fyneworks插件 ,但是文件名未以使用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 Mmm..yeah尚未完成,因为当我尝试使用imageNow类生成另一个Inputfile时$('。imageNow')。change(function()不再起作用了,有人可以帮助我吗?谢谢

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. 当我尝试使用imageNow类生成另一个Inputfile时,$('。imageNow')。change(function()将不再起作用。

but to solve this one you have to use .live : 但是要解决这一问题,您必须使用.live

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM