Any event triggered on autocomplete?

前端 未结 8 1971
余生分开走
余生分开走 2020-11-27 15:39

I have a pretty simple form. When the user types in an input field, I want to update what they\'ve typed somewhere else on the page. This all works fine. I\'ve bound the

8条回答
  •  庸人自扰
    2020-11-27 16:03

    I've realised via monitorEvents that at least in Chrome the keyup event is fired before the autocomplete input event. On a normal keyboard input the sequence is keydown input keyup, so after the input.

    What i did is then:

    let myFun = ()=>{ ..do Something };
    
    input.addEventListener('change', myFun );
    
    //fallback in case change is not fired on autocomplete
    let _k = null;
    input.addEventListener( 'keydown', (e)=>_k=e.type );
    input.addEventListener( 'keyup', (e)=>_k=e.type );
    input.addEventListener( 'input', (e)=>{ if(_k === 'keyup') myFun();})
    

    Needs to be checked with other browser, but that might be a way without intervals.

提交回复
热议问题