开发者

JQuery/DOM event for typing Chinese (ibus)?

开发者 https://www.devze.com 2023-04-01 13:39 出处:网络
as we know there is a lot of events will be triggered when we typing. such as keyup, keydown, keypress or someth开发者_JS百科ing else.

as we know there is a lot of events will be triggered when we typing.

such as keyup, keydown, keypress or someth开发者_JS百科ing else.

Is there any other event will be triggered only when the content in the text field is changed? and if there is not,how to write some javasrcipt code to accomplish this feature


The change event might help?


I've created a simple fiddle to determine what happens when a text node in a contenteditable element is modified by a key press. As I was doing that, I decided to check what happens when using ibus because I use ibus for my own work. I determined that when ibus is used, the only keyboard event generated is a keyup event with a which value which is useless.

Here is the fiddle I created:

http://jsfiddle.net/lddubeau/jWnL3/

  1. Go to that fiddle.

  2. Turn on your Javascript console.

  3. Click run.

  4. Click between the 2dn and third character of the word "toto".

  5. Type something using ibus. For instance, type 我.

  6. The output varies depending on your browser. On Chrome 29 each keystroke is recorded so if I type 我 using the tonepy method I get keyup and keydown for each of the "w" "o" "3" and "1". (The pinyin, the tone and then hitting 1 to select the first choice.) The final event is:

    event type: keyup
    which: 229
    keyCode: 229
    charCode: 0
    node value: 
       to我to
    

    The events before this one all have the same values except that some are of the "keydown" type and of course the node value shows "toto" until the last event.

    On Firefox 23 only one event is registered:

    "event type:" "keyup"
    "which:" 49
    "keyCode:" 49
    "charCode:" 0
    "node value:" "
        to我to
    "
    

    No keydown or keypress events are generated. (When typing characters within the ascii range, you get keydown, keypress and keyup for each key.)

The values of which and keyCode do not seem to correspond to anything sensible. I've examined the event object passed to the event handler and did not see any field which would indicate that the user just typed 我.

0

精彩评论

暂无评论...
验证码 换一张
取 消