Any event triggered on autocomplete?

前端 未结 8 1988
余生分开走
余生分开走 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:04

    The only sure way is to use an interval.

    Luca's answer is too complicated for me, so I created my own short version which hopefully will help someone (maybe even me from the future):

        $input.on( 'focus', function(){
            var intervalDuration = 1000, // ms
                interval = setInterval( function(){
    
                    // do your tests here
                    // ..................
    
                    // when element loses focus, we stop checking:
                    if( ! $input.is( ':focus' ) ) clearInterval( interval );  
    
                }, intervalDuration );
        } );
    

    Tested on Chrome, Mozilla and even IE.

提交回复
热议问题