There was a need some time ago to create a selection input box, similar to Baidu's search box. Since I am also a novice, I have found a lot on the Internet, and here are two relatively easy-to-use implementation methods.
The first one: Based on the new features of html5
The effect is as shown in the figure below
The key code of jsp is given below.
What needs to be noted here is that the id of datalist must be consistent with the value of the list attribute of input. The purpose of the oninput event and onpropertychange event is to call methods to fill the datalist value when the input box value changes.
function OnInput (event) { //alert ("The new content: " + event.target.value); var vendorStr = event.target.value; changeOption(vendorStr); } // Internet Explorer function OnPropChanged (event) { if (event.propertyName.toLowerCase () == "value") { var vendorStr = event.srcElement.value; changeOption(vendorStr); } } function changeOption(vendorStr){ //1.通过vendorStr模糊查询出5个供应商 var url="${ctx}/scm/vendorInfo/getVendorName"; $.post( url, {"vendorStr":vendorStr}, function(date){ //清空之前的Option $("#vendors").empty(); //2.返回结果加入到Option中 for(var i =0;i<date.length;i++){ $("#vendors").append('<option value="'+date[i]+'"></option>'); } }, "json" ); }
It is relatively simple to use the datalist tag of html5 to implement the selection input box, but there is a problem, that is, html5 does not support IE8 and below. So the second method is given below. Supporting IE8
This method can be said to be borrowing flowers to offer to Buddha. It uses a third-party plug-in
. The idea is actually similar. It is to dynamically obtain the value of the text box, then use ajax request, fuzzy query the data in the background, and then return to the front desk for display. As for efficiency issues, the amount of data in this project is 10W. Before doing it, I also considered whether the like query speed would be too slow. The truth comes from practice. If you directly use like to query the first 5 items (you can't display so much data, so I will display up to 5 items of data in the selection box), the speed is not slow at all. If you encounter efficiency problems, please ask the experts for advice.
The above is the detailed content of Choose how the input box is applied. For more information, please follow other related articles on the PHP Chinese website!

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Dreamweaver CS6
Visual web development tools

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),

Zend Studio 13.0.1
Powerful PHP integrated development environment