Why is my onchange function called twice when using .focus()?

前端 未结 6 2060
执念已碎
执念已碎 2021-01-20 09:32

TLDR

  • Check this example in chrome.
  • Type someting and press tab. see one new box appear
  • type something and pr
6条回答
  •  佛祖请我去吃肉
    2021-01-20 10:10

    maybe this some help to anybody, for any reason, in chrome when you attach an event onchage to a input text, when you press the enterkey, the function in the event, do it twice, i solve this problem chaged the event for onkeypress and evaluate the codes, if i have an enter then do the function, cause i only wait for an enterkey user's, that not works for tab key.

        input_txt.onkeypress=function(evt){ 
                evt = evt || window.event;
                var charCode = evt.which || evt.keyCode;
                if(charCode === 13)  evaluate( n_rows ); 
                 };
    

提交回复
热议问题