简体   繁体   中英

How can I put an input in the top of select tag for searching?

I'm trying to make an advanced <select> tag but implementing an input before the first <option> attribute for searching. Something like this:

在此处输入图片说明

Here is my code. How can I add <input name="search_category" class="search" /> to my code?

 select { width: 50%; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select size="1" class="selection"> <option>Social</option> <option>Political</option> <option>Cultural</option> <option>Athletic</option> <option>Other</option> </select> 

Note: I use jQuery.

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_datalist

This should solve it, if I understood the question correct.

Have you tried the jquery select2 ?

https://select2.github.io/

I think it will easily solve your problem :)

Not Jquery, but you can use datalist

 <style> input { font-size:1.5em; } </style> <input type="text" placeholder="Select" name="cat" list="cat"> <datalist id="cat"> <option>Social</option> <option>Political</option> <option>Cultural</option> <option>Athletic</option> <option>Other</option> </datalist> 

Note: In chrome you will get the select icon, but may not be mozilla

You can use select2 jquery plugin method to implement dropdown with search functionality.

Here the link with the example.

Hope this one is helpfull.

I made good experiences using a plugin called Chosen : https://harvesthq.github.io/chosen/

Or Select2 : https://select2.github.io/

If a jQuery dependency is ok...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM