


Implementing autocomplete to automatically complete forms based on bootstrap plug-in_javascript skills
Based on the bootstrap plug-in, autocomplete automatically completes the form, providing script code, use cases, and backend server (php). There are some things that are not clear in the original text. I hope it can help everyone.
First of all, you must load bootstrap&jquery. What needs additional explanation is that the two-dimensional array returned by the backend should be consistent with the call below the formatItem method;
In addition, the returned data must be parseJSON first! Remember.
Related parameter description:
source: function(query,process){}. query represents the string in the current text input box. In this method, you can request data (json object in the form of an array) from the background through ajax, and then use the returned object as a parameter of the process;
formatItem: function(item){}. Convert a specific json object of the returned data into a string format to be displayed in the prompt list. Return value: string;
setValue: function(item){}. When an item in the prompt list is selected, set the value displayed in the text input box and the actual value to be obtained. Return value format: {'data-value':item["The item attribute of the value displayed in the input box"],'real-value':item["The item attribute of the actual value that needs to be obtained"]}, which can be used later through the text input box The real-value attribute gets the value;
items: The maximum number of result sets for auto-complete prompts, default: 8;
minLength: Matching will only be performed when the string in the current text input box reaches this attribute value. Default: 1;
delay: Specify the number of milliseconds before actually requesting data from the background to prevent frequent requests to the background caused by too fast input. Default: 500
Implement autocomplete to automatically complete the form based on bootstrap plug-in, the code is as follows
1. Code
<script> $('#sim_iccid').autocomplete({ source:function(query,process){ var matchCount = this.options.items;//允许返回结果集最大数量 $.get("http://www.soyiyuan.com/update/",{"iccid":query,"matchCount":matchCount},function(respData){ respData = $.parseJSON(respData);//解析返回的数据 return process(respData); }); }, formatItem:function(item){ return item["iccid"]+"("+item["mobile"]+")"; }, setValue:function(item){ return {'data-value':item["iccid"],'real-value':item["mobile"]}; } }); </script>
2. $data is a two-dimensional array
echo json_encode( $data )
3. Standard json format that needs to be returned
[code][{"iccid":"12345678901234567890","mobile":"1850000"},{"iccid":"12345785","mobile":"1850001"}][code]
Bootstrap autocomplete control Autocomplete is based on bootstrap's own control typeahead, because typeahead does not support complex objects.
//示例代码如下: $('#autocompleteInput').autocomplete({ source:function(query,process){ var matchCount = this.options.items;//返回结果集最大数量 $.post("/bootstrap/region",{"matchInfo":query,"matchCount":matchCount},function(respData){ return process(respData); }); }, formatItem:function(item){ return item["regionName"]+"("+item["regionNameEn"]+","+item["regionShortnameEn"]+") - "+item["regionCode"]; }, setValue:function(item){ return {'data-value':item["regionName"],'real-value':item["regionCode"]}; } }); $("#goBtn").click(function(){ //获取文本框的实际值 var regionCode = $("#autocompleteInput").attr("real-value") || ""; alert(regionCode); });
The above is the entire content of this article, I hope it will be helpful to everyone’s study.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The main reasons for displaying garbled code on Bootstrap Table are character set mismatch, encoding problems and poor browser compatibility. Solutions include: 1. Confirm character set consistency; 2. Check data transmission encoding; 3. Replace a browser with better compatibility; 4. Update the Bootstrap Table version; 5. Confirm the data format is correct; 6. Clear the browser cache.

The file upload function can be implemented through Bootstrap. The steps are as follows: introduce Bootstrap CSS and JavaScript files; create file input fields; create file upload buttons; handle file uploads (using FormData to collect data and then send to the server); custom style (optional).

Check and fix Bootstrap Table data source encoding by following these steps: Get the data source and convert it to a string. Use encodeURIComponent() to check the encoding; if it is different, it means that the encoding is not correctly encoded. Use encodeURI() to encode the data source and load it into the Bootstrap Table.

Creating a carousel chart using Bootstrap requires the following steps: Create a container containing a carousel chart, using the carousel class. Add a carousel image to the container, using the carousel-item class and the active class (only for the first image). Add control buttons, using the carousel-control-prev and carousel-control-next classes. Add a carousel-indicators metric (small dots), using the carousel-indicators class (optional). Set up automatic playback and add data-bs-ride="carousel&"on the carousel" container.

Bootstrap supports four list styles: unstyled lists, ordered lists, unordered lists (all are default styles), and inline lists that can be used to create horizontal navigation menus and tag clouds. In addition, Bootstrap also provides a powerful list-group class that creates lists with rounded corners, borders, and background colors for displaying project lists or navigation menus.

To create a Bootstrap framework, follow these steps: Install Bootstrap via CDN or install a local copy. Create an HTML document and link Bootstrap CSS to the <head> section. Add Bootstrap JavaScript file to the <body> section. Use the Bootstrap component and customize the stylesheet to suit your needs.

Bootstrap provides a simple guide to setting up navigation bars: Introducing the Bootstrap library to create navigation bar containers Add brand identity Create navigation links Add other elements (optional) Adjust styles (optional)

The size of a Bootstrap list depends on the size of the container that contains the list, not the list itself. Using Bootstrap's grid system or Flexbox can control the size of the container, thereby indirectly resizing the list items.
