Javascript implementation text box drop-down prompt (smart prompt) effect

Source: Internet
Author: User

When you often search for something in a browser, you will surely find that Baidu will have a smart drop-down prompt as long as you enter a word at will, and feel that the experience is quite good!
However, I don't know how to implement it, so I don't have to worry about it. The following describes a simple and lightweight method, which can be directly downloaded and used after files have been sorted out:

The implementation result is as follows: Reference File: jquery. js autoComplete. js

Css

<Style type = "text/css">
Ul, li {margin: 0; padding: 0; list-style-type: none ;}
A: hover {text-decoration: underline ;}
. Txt {width: 210px; height: 25px; border: 1px solid # ccc; line-height: 25px; padding: 0 5px ;}
. AutoDis {border: 1px solid #999; position: absolute; overflow: hidden; display: none ;}
. AutoDis p {line-height: 25px; cursor: default; padding: 0 5px ;}
. AutoDis li {line-height: 25px; cursor: default; padding: 0 5px; background-color: # fff ;}
. AutoDis. cur {background: # ccc ;}
</Style>

Html

<Div id = "wrap">
<Input id = "autoCom" type = "text" class = "txt">
</Div>

Javascript

<Script type = "text/javascript">
Var cnames ('.txt ');
Var data = ['20160301', '20160301', '20160301', '20160301', '20160301', 'www .ljiong.com '];
Var aaa = new autocom (data );
Aaa. autoComplete. init (). bind (c );
</Script>

The effect is as follows:

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.