简体   繁体   English

如何将输入放在选择标签的顶部以进行搜索?

[英]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. 我正在尝试制作高级的<select>标记,但是在第一个<option>属性进行搜索之前实现了输入。 Something like this: 像这样:

在此处输入图片说明

Here is my code. 这是我的代码。 How can I add <input name="search_category" class="search" /> to my code? 如何在代码中添加<input name="search_category" class="search" />

 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. 注意:我使用jQuery。

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_datalist 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 ? 你尝试过jQuery select2吗?

https://select2.github.io/ https://select2.github.io/

I think it will easily solve your problem :) 我认为它将轻松解决您的问题:)

Not Jquery, but you can use datalist 不是Jquery,但是您可以使用数据列表

 <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 注意:在chrome中,您将获得选择图标,但可能不是mozilla

You can use select2 jquery plugin method to implement dropdown with search functionality. 您可以使用select2 jquery插件方法来实现具有搜索功能的下拉菜单。

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/ 我使用名为Chosen的插件取得了很好的经验: https : //harvesthq.github.io/chosen/

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

If a jQuery dependency is ok... 如果jQuery依赖关系还可以...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 select 和 VueJS 中的输入之间放置空格? - How can I put space between a select and a input in VueJS? 当我 select 输入框时,如何将“您正在输入数字”放在输入框的正下方? - How can i put "you are entering a number" right below the input box when i select input box? 如何确保在输入字段中输入新数字时脚本/<p> 标签刷新? - How can I make sure when I put a new number in input field the script/ <p> tag refreshes? 如何使用 JavaScript\\JQuery 使用选择标记的选定选项的值设置隐藏输入标记的值? - How can I set the value of an hidden input tag with the value of the selected option of a select tag using JavaScript\JQuery? 我可以放吗 <input> 在insertRow()函数中标记? 不只是文字 - Can I put <input> tag in insertRow() function? Not only text 如何给输入标签赋值 - How to put value to the input tag 我怎样才能把选择的选项 <select>从动态生成的表单到输入字段 - How can I put the selected option of a <select> from a dynamically generated form into an input field 如何将 select 标签中的选项传递给另一个 select 标签? - How can I pass an option in a select tag to another select tag? 如何在 alert() 框中输入输入? - How can I put an input in the alert() box? 如何将 1 个日期放入 2 个输入字段? - How can I put 1 date into 2 input fields?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM