Switching between input methods between HTML input

2019-05-17 09:30发布

问题:

I have an HTML form with two input textfields.

When the user tabs from the first field to the second, I'd like to automatically switch the user's input method to a different one, say for a different language.

The reason I'm trying to do this is that I expect the user to type content in known different languages in each field.

I tried <input lang="JA" /> but that didn't seem to change the input method on Safari for Mac nor iOS.

Is it possible in HTML or JavaScript to change the input method on a per-textfield basis?

回答1:

Input methods are controlled by the browser and the user. The lang attribute does not affect this, and there is no other HTML way either. It would not be useful to change the input method on a per-document, still less per-field basis, from the method normally used in the browser and accepted by the user (either silently or by finding out how to control such things).

In some situations, it can be helpful to provide special tools to users—not to override input methods but to offer additional possibilities. For example, if the expected language is written in Latin letters with a few extra letters in addition to the basic a–z, you could have buttons for entering them (to help people using keyboards that have no convenient way to type them).

It is possible to build controls that act as input method editors, see e.g. typd.in for entering Japanese. But this means using something on top of the input methods that the user is using.