简体   繁体   中英

After JQuery on() is called, embed javascript stops running

I've tried this several different ways, at one point I had the .on call isolated to one line of code, and put console.write() messages before and after, the write messages don't fire after the on() is called. Scripts after this script's tag work fine.

Javascript is 1.2. Maybe it's too old?

$("body").on("change", ".media_frm", function(e)
{

    if(e.target.value.length == 0) return true; //if blank or undefined, it's okay
    var filename = e.target.value.match(/([^<\>\:\"\/\\\|\?\*])+$/i)[0]; //get rid of erroneous filepath
    var filetype = filename.match(/[^.]+$/i)[0]; //get extension after '.'
    if($.inArray(filetype, allowedExtensions) === -1)
    {
       alert("Invalid File Type: " + filename); 
        e.target.value = "";
        return false;
    }
    return true;

});

Like I said, I've also set the above to a function, and just called on() on the element directly, like:

$(elem).on("change", verifyFunction);

and everything after this line will stop running, just like how everything stops running with the above block of code.

JQuery 1.6 does not support .on(). I have to use .bind().

$("body").bind("change", ".media_frm", function(e)
{

    if(e.target.value.length == 0) return true; //if blank or undefined, it's okay
    var filename = e.target.value.match(/([^<\>\:\"\/\\\|\?\*])+$/i)[0]; //get rid of erroneous filepath
    var filetype = filename.match(/[^.]+$/i)[0]; //get extension after '.'
    if($.inArray(filetype, allowedExtensions) === -1)
    {
       alert("Invalid File Type: " + filename); 
        e.target.value = "";
        return false;
    }
    return true;

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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