PHP + jQuery realize automatic complementing full-featured Source code

Source: Internet
Author: User
Previously, I manually wrote a drop-down auto-completion function, which is easy to write and only enables mouse selection. keyboard selection is not supported, next, I will share with you the PHP + jQuery auto-completion feature. I wrote a pull-down auto-completion feature, which is simple to write and only enables mouse selection. the keyboard selection is not supported. This function is used in many projects, so you need to do it carefully. It is found that the function of the select2 plug-in can meet the current needs.

When using the jquery plug-in select2, I encountered some questions. both json data and jsonp data retrieval can be returned correctly. However, the entries in the drop-down list cannot be selected, and the selection of the mouse and keyboard is invalid.

Later, it was found that the select2 plug-in was selected based on the id field in the data. Therefore, no matter json or jsonp, the data returned by ajax must have an id field. If such an id does not exist in the actual database, you can create one manually, but ensure the uniqueness of the id.

The source code of the template file try_diy.tpl is listed here.:
The colum input box serves as the plug-in, but the returned value is id. after the page is submitted, we need to re-present the selected Forum to the user, my approach is to query the corresponding layout name based on the id submitted by the form. when the controller receives the id value and is not empty, the name value corresponding to the Forum id is displayed on the page at the same time. Because the select2 plug-in places the name in the constructed

In the span element of the inner layer, I will load the query result page and write the name value of the hidden domain to the span element.

The code is as follows:






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.