javascript - How can I put an input in the top of select tag for searching? - Stack Overflow

I'm trying to make an advanced <select> tag but implementing an input before the first <o

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=".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>

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./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.

Share Improve this question asked Jan 26, 2017 at 13:03 stackstack 10.2k22 gold badges70 silver badges130 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

http://www.w3schools./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...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744785642a4593608.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信