JQuery. autocomplete supports the Chinese Input (firefox) Correction Method

Source: Internet
Author: User

However, the only pity is that when the Chinese Input Method is enabled, firefox3.0 automatically matches Chinese pinyin, And the entered Chinese cannot be triggered in time; in my IE6.0, there is no such problem.

Cause analysis:
The Autocomplete plug-in triggers automatic matching of user input characters through the "keydown" event (Analysis of jquery. autocomplete. js line 92nd). in IE6, when the input method is enabled, the input character does not trigger the "keydown". It is triggered only after the Chinese input is complete, therefore, there is no difference between Chinese Input and latin. However, in firefox3.0, no matter whether the input method is enabled or not, the "keydown" event is triggered by pressing the key. Therefore, the Chinese input is complete, the system automatically matches some Chinese pinyin letters. ------ So there is only a problem with Firefox.

Solution:
The most common method found on the Internet is to modify jquery. autocomplete. line 3 of js will replace "keydown" with "keyup", but this is not the fundamental method. After this change, you can automatically match the entered Chinese in firefox in a timely manner, however, the important event mechanisms such as carriage return and tab in the original plug-in are damaged. For example, if your input is in a form, press enter to directly submit the form from the original input to input. This is not what we want.

My method principle is to add an event that the original plug-in triggers the query, that is, when the character in the input column changes, re-query (call its internal onChange function ), this is mainly for firefox, because the most accessed systems are IE and firefox. In firefox, an input change event is oninput, so we only need to insert the event in line 199th of the original jquery. autocomplete. jsThe following code:
. Bind ("input", function (){
// @ Hack: support for inputing chinese characters in firefox
OnChange (0, true );
});


After insertion, the code is roughly as follows:

...
...
JQueryinput. unbind ();
JQuery (input. form). unbind (". autocomplete ");
}). Bind ("input", function (){
// @ Hack: support for inputing chinese characters in firefox
OnChange (0, true );
});
...

2. Multiple carriage returns are supported:
Modify 91 rows:
// Only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
$ Input. bind ($. browser. opera? "Keypress": "keydown") + ". autocomplete", function (event ){
To:
// Only opera mozilla doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
$ Input. bind ($. browser. opera | $. browser. mozilla )? "Keypress": "keydown") + ". autocomplete", function (event ){

Related Article

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.