Javascript onchange different in IE and FireFox

后端 未结 3 782
花落未央
花落未央 2021-01-24 22:21

When this onchange event in IE returns false, IE focus stays on that input box. In Firefox the focus always moves to the next field regardless.

HTML:

i         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 23:04

    A response that no longer appears to be here suggested 'timing' issues, albeit on a slightly different subject. So I googled 'timeout' and found Mike Rankin's blog from 2005 which allowed me to solve the issue by changing focus() to:

    var t= setTimeout('document.getElementById("seminar_donation").focus()',1);
    

    So what happens is Firefox still goes on to the next field, but 1 msec later, this code sets the focus back to the errant field. It is cludgy because if that next field has an oblur event that onblur will get triggered when the timeout forces the focus back. But it is a work-around for apparently a long standing bug in Firefox.

提交回复
热议问题