Modify the jquery plug-in AutoComplete to implement on-demand manual carriage return Query

Source: Internet
Author: User

Jquery-based AutoComplete is an automatic query completion plug-in. Based on user input, it communicates with the background in real time through Ajax, and returns appropriate content to generate a selectable list for use to complete the completion auxiliary function. It has more detailed options to set. If you want to use it, you can first look at the official instructions.

 

This article discusses the necessary modifications as needed. For example, to reduce unnecessary queries and reduce the pressure on databases and servers for frequent searches, the use of minchars is very limited.

In the following method, you can modify the JQ. AutoComplete source code to change the key processing logic, move the Enter key function to a vacant Tab key, and use the return key as the function key for manual query. Normal buttons will no longer stimulate queries.

 

1. Open JQ. AutoComplete and find case key. Tab:

2. After finding it, replace the following code with the corresponding location of the source code:

Case key. tab: If (selectcurrent () {// stop default to prevent a form submit, opera needs special handling event. preventdefault (); blocksubmit = true; return false;} break; Case key. return: cleartimeout (timeout); timeout = setTimeout (onchange, options. delay); break; default: break;

Reprinted please indicate from http://blog.csdn.net/theforever/article/details/8053963

If there is time, you can rewrite this function to an extension option of JQ. AutoComplete to control whether to query automatically or manually. You only need to add an option and make judgments in the three cases. This is just a solution to a specific question, and you are not in the mood to write anything else (you have done the same for a long time ). If you are interested, you can perform expansion on your own.

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.