Instant Search: Processing of input events triggered multiple times when iOS comes in Chinese

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.