最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Form input loses focus on scroll bar click in IE - Stack Overflow

programmeradmin3浏览0评论

I hope someone can help me. I know this has been discussed here before but the example is prototype and foreign to me. I'm looking for a strict javascript or jquery solution. I have an example setup here. Click on the scrollbar in FF and you don't get an alert but click on it in IE and you do. Please help me, thanks!

I hope someone can help me. I know this has been discussed here before but the example is prototype and foreign to me. I'm looking for a strict javascript or jquery solution. I have an example setup here. Click on the scrollbar in FF and you don't get an alert but click on it in IE and you do. Please help me, thanks!

Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked Feb 17, 2010 at 21:30 Justin BullJustin Bull 8,2156 gold badges29 silver badges31 bronze badges 2
  • FYI Chrome's behavior seems to be the same as IE's – Emmett Commented Feb 17, 2010 at 21:36
  • @emmett I am unable to reproduce this issue on Chrome in the latest version, might have changed in newer versions. – Rob Evans Commented Sep 4, 2013 at 7:38
Add a ment  | 

2 Answers 2

Reset to default 6

After some searching I came up with this answer. From the best of my knowledge, you cannot actually cancel the blur event, nor can you call the focus event at the same time. This is what I don't get .. you can blur on focus but you cannot focus on blur .. Anyway my solution is use the setTimeout function to call the focus event 1ms after the focus was lost.

var o = this;
oTimeout = setTimeout(function(){
    o.focus();
},1);

Using mouseenter and mouseleave events, I set a boolean to refer to on blur event

$("div#box").mouseenter(function(){
    changeFocus(1);
}).mouseleave(function(){
    changeFocus(0);
});

I've had the same problem and this works for what need it to do. Just force the focus back on the element.

$('#divWithScrollBar').scroll(
    function () {
        $('#elementThatLosesFocus').focus();
    });

That event is somehow triggered after the element is blurred, but before the onblur event is kicked in. Haven't really looked in to it, but that's what seems to be going on.

The scroll does appear a bit slow, but it works.

IE owes me many hours of my life back.

发布评论

评论列表(0)

  1. 暂无评论