Makzan / I share what I learned

keyup event and Chinese input in mobile Safari

A student of mine asked me this question when he is making an input text filtering with Chinese content. The user needs to input some text to filter the content. Here is his original code:

$('#search').bind('keyup', function(){...})

In Chinese input, we often compose one block character by composing strokes. When typing Chinese text in <input>, this last selection won’t fire the keyup event. For the event that user has selected a Chinese text, we listen to the input event:

$("#search").bind('keyup input', function() { ... })

The input event fires when the text displayed in the <input> changes. So even the Chinese character doesn’t count as a keyup, it changes the input display and count as an input event.

What if we are just handling English character? Do we need the inputevent too?

We may still need the input event to target the value changes made by copy & paste string with right click, which obviously won’t count as keyup.


Published on 2015-10-02. More articles like this:
- Web Technologies

Previous <- How to undo (almost) anything with Git
Next -> Saying No

📬 Subscribe to Makzan’s Weekly Dispatch

Want productive tips and web technologies links like this in your inbox each week? Sign up for weekly dispatch each week. No spam ever. Just useful content:

What to expect: If you wish to withdraw your consent and stop hearing from us, simply click the unsubscribe link at the bottom of every email we send or contact us at mak@makzan.net. We value and respect your personal data and privacy. To view our privacy policy, please visit our website. By submitting this form, you agree that we may process your information in accordance with these terms.