jQuery blur() or focusout() not firing in Internet Explorer

风格不统一 提交于 2019-12-11 02:38:24

问题


So I have this form and I would like to do some stuff when the inputs loose focus. This is the code I have and it's working like a champ in every browser except Internet Explorer.

function formstyle() {

    var focus = 0;

    //comentario is the ID of the input
    $("#comentario").focus(function() {
        //blablablabla
    });

    $("#comentario").blur(function() {
        setTimeout(function() {
            var whatFocus = document.activeElement.tagName;

            if (whatFocus === "BODY") {
                focus = 0;
                //bla bla bla
            }
        }, 2);
    });
}

$(document).ready(function(){
    formstyle();
});

I'm almost blowing up my mind. It's a simple piece of code and yet… nothing… Did I miss anything?


回答1:


Did you try using focusout? http://api.jquery.com/focusout/

$("#comentario").focusout(function() {
    setTimeout(function() {
    var whatFocus = document.activeElement.tagName;

    if(whatFocus === "BODY")
    {
        focus = 0;
        //bla bla bla
    }
    }, 2);
});



回答2:


Oky… After hours trying every idea, even the the most strange ones, with no luck, i asked my gf for her computer and so i tried it there and all worked like a charm… :/ Pretty weird…

I just had to add a "DIV" part to the if conditional block to make the code inside it to work in IE9 and bellow, but the "focusout" thingy worked on the other computer with no issues.

I'm guessing my IE installation has some problems. Can't see any other explanation.

Anyway, thanks for all the help guys!



来源:https://stackoverflow.com/questions/19073602/jquery-blur-or-focusout-not-firing-in-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!