问题
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