search
HomeBackend DevelopmentPHP TutorialPHP+jQuery implements automatic completion function source code_PHP tutorial

I manually wrote a drop-down auto-completion function earlier. It is simple to write and only implements the mouse selection function and does not support keyboard selection. Since this function is used in many places in the project, it needs to be done carefully. It is found that the function of the select2 plug-in can meet the current needs.

I encountered some doubts when using the jquery plug-in select2. Whether it is passing through json data or fetching data through jsonp, it can be returned correctly. However, the items in the drop-down list cannot be selected, and neither mouse nor keyboard selection is valid.

Later I discovered that the select2 plug-in implements selection based on the id field in the data. So whether it is 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 also construct one manually, but the uniqueness of the ID must be ensured.

Here is the source code of the template file try_diy.tpl:
The column input box is where the plug-in works, but the value returned is the id, which we need after the page is submitted Re-present the section selected by the user to the user. My approach is to query the corresponding section name based on the id submitted in the form. When the controller receives the id value and it is not empty, the name value corresponding to the section id is presented to the user at the same time. displayed on the page. Since the select2 plug-in puts the name in the inner span element of the constructed

, I will write the name value of the hidden field into span element.
Copy code The code is as follows:







Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),