Home > Web Front-end > JS Tutorial > jQuery.autocomplete supports Chinese input (firefox) correction method_jquery

jQuery.autocomplete supports Chinese input (firefox) correction method_jquery

WBOY
Release: 2016-05-16 18:09:41
Original
1070 people have browsed it

But the only regret is that when the Chinese input method is turned on, firefox3.0 automatically matches Chinese pinyin, but cannot trigger matching in time for input Chinese; while under 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 (line 92 of jquery.autocomplete.js can be analyzed). In IE6, when the input method When it is turned on, the entered characters will not trigger "keydown". It will only be triggered after the Chinese input is completed, so there is no difference between Chinese input and Latin input; but under Firefox3.0, regardless of whether the input method is turned on or not, the keydown will be triggered." keydown" event, so after the Chinese input is completed, some of the Chinese Pinyin letters just typed will be automatically matched. ------So only Firefox has a problem.

Solution:
The most common method found on the Internet is to modify line 92 of jquery.autocomplete.js and replace "keydown" with "keyup", but this is not the fundamental solution, although it can be improved after this change. In Firefox, the input Chinese is automatically matched in a timely manner, but the important event mechanisms such as carriage return and tab in the original plug-in are destroyed. For example, after this change, if your input is in a form, carriage return will be changed from the original Entering the selected items into the input becomes directly submitting the form, which is not what we want.

The principle of my method is to add an event that the original plug-in triggers the query, that is, when the characters in the input input field change, the query is re-queried (calling its internal onChange function). This is mainly for firefox. Because our system is most accessed by IE and firefox. Firefox happens to have an input change event called oninput, so we only need to insert the following code in line 199 of the original jquery.autocomplete.js:
.bind("input", function() {
// @hack:support for inputing chinese characters in firefox
onChange(0, true);
});


After insertion, the code is as follows:

...
...
jQueryinput.unbind();
jQuery(input.form).unbind(".autocomplete");
}). bind("input", function() {
// @hack:support for inputing chinese characters in firefox
onChange(0, true);
});
...

2. Support multiple enter selections:
Modify line 91:
// 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) {
Modify 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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template