The best way to achieve real-time mobile search, must be using the input PropertyChange event, but on the iOS device encountered a problem, using iOS to input Chinese characters with input method, there will be multiple triggering the input event, the first may be due to search for the keyword is not law, Did not immediately find the right solution, and then finally found the solution on the Internet, now recorded as follows:
Code implementation
/*** @param flag:used to mark whether non-direct text input*/varFlag= false;$(' #id '). on({ ' Compositionstart ': function(){Flag= true; }, ' Compositionend ': function(){Flag= false; if(!Flag{ //do something ... dosomethingfunction(); } }, ' Input PropertyChange ': function(){ if(!Flag{ //do something ... dosomethingfunction(); } }});
- Implementation principle: With Compositionstart and compositionend two events as a switch, and with the help of state variables, only after the end of the text input to trigger the input event
- After using this method, if you just need to enter the English language, then you need to click enter OK to trigger
Source of reference: https://www.cnblogs.com/dubox/p/5997969.html
Instant Search: Processing of input events triggered multiple times when iOS comes in Chinese