Javascript onchange different in IE and FireFox

后端 未结 3 783
花落未央
花落未央 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.

    0 讨论(0)
  • 2021-01-24 23:11
    setTimeout('document.getElementById("seminar_donation").focus()',1);
    
    0 讨论(0)
  • 2021-01-24 23:20

    Have you tried adding a "return" in the onchange attribute? i.e.

    <input name="seminar_donation" type="text" id="seminar_donation" onchange="return CheckTotal(this);">
    

    I'm not entirely sure that this would work, but worth a try?

    Edit: to clarify, the reason I'm not sure is that I'd usually approach this differently and bind the event handler in javascript rather than html.

    0 讨论(0)
提交回复
热议问题