Implementation of select Dropdown based on jquery select optional source download _jquery

Source: Internet
Author: User
Tags jquery library

As we know, the General Select dropdown box is only selectable and cannot be used to enter content. And sometimes we encounter a drop-down box with no information items to select or Drop-down options for a very long time, we can let select into text, allowing users to enter the desired content, but also in the input when the keyword will be included in the list, for quick selection.

View Demo effect Source download

This article will use an example to share a jquery based on the dropdown box plug-in, which allows users to enter content, while the Drop-down options in time to match the relevant options, support keyboard operations, but also support the content of HTML options, of course, can make the process with the Drop-down animation effect. Let's take a look at how to use.

HTML structure

The following is a basic select Drop-down box.

<select id= "Editable-select" > 
<option>alfa romeo</option> 
<option>audi</ Option> 
<option> PBC </option> 
<option> Chinese people </option> 
<option> China </option> 
<option>BMW</option> 

Also need to load jquery library and Jquery.editable-select.js files, in the source download package already have.

Jquery

Only the following code is required to implement the traditional dropdown box into a drop-down box with input function.

$ (' #editable-select '). Editableselect ({ 
effects: ' Slide ') 

In fact, we look at the plug-in code will find that the author is the original select processing, into a single input form text and a list of UL. This text can be entered, the dropdown option is used with the UL panel, so that the UL option can add arbitrary HTML code, demo has examples. Then through the use of CSS and JS technology can achieve Drop-down pop-up, input lookup matching function.

Option settings

Filter: Filtering, that is, when the input content of the pull option will match the input characters, support Chinese, true/false, default true.
Effects: Animation effect, when triggered pop-up drop-down selection box when the Drop-down box to show the transition effect, there are default,slide,fade three values, defaults to default.
Duration: The transition animation speed shown in the dropdown box, with Fast,slow, and number (milliseconds), is fast by default.

Event

OnCreate: triggered when input.
OnShow: Triggers when the current pull.
Onhide: Triggers when the Drop-down box is hidden.
Onselect: triggered when the option in the Drop-down box is selected.

Event Invocation Method:

$ (' #editable-select '). Editableselect ({ 
onselect:function (element) { 
alert ("selected!"); 
} 

The above content to share the core code, need the source of friends can directly download oh.

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.