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: