javascript 带过滤器的 HTML 选择字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15013559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:10:16  来源:igfitidea点击:

HTML select field with filter

javascriptjqueryhtml

提问by user987055

I have a select field where a large amount of published names, could reach hundreds.

我有一个选择字段,其中大量已发布的名称可能达到数百个。

What I need is to filter the field, I mean:

我需要的是过滤该字段,我的意思是:

That if one was selected and searched, displayed as sample texts for forms and with the possibility of writing a new search deleting the sample text searched before.

如果选择并搜索一个,则显示为表格的示例文本,并且可以编写新的搜索删除之前搜索的示例文本。

That fence as typing the text in the box will display the filtered list of options for the text.

在框中键入文本时,该栅栏将显示过滤后的文本选项列表。

An example would be: if I type D or d in the text box, it displays the list of options Daniel Diego, so for all, and that if you search with Diego then after loading the search text box appears as example Diego.

一个例子是:如果我在文本框中输入 D 或 d,它会显示选项列表 Daniel Diego,所以对于所有,如果你用 Diego 搜索,然后在加载搜索文本框后显示为示例 Diego。

<select id="id_name" name="name">
    <option value="3">Diego </option>
    <option value="4">Daniel  </option>
    <option value="5">Fernando  </option>
    <option value="6">Luz </option>
    <option value="7">Catherine  </option>
    <option value="8">Samuel  </option>
    <option value="10">Eduardo  </option>
</select>

回答by Ryan Fitzgerald

Try this.

试试这个。

Chosen is a jQuery plugin for the <select>html tag.

Chosen 是一个用于<select>html 标签的 jQuery 插件。

Not only does it make your select boxes look nicer, but it adds a very nice search feature at the top of the select box.

它不仅使您的选择框看起来更好看,而且在选择框的顶部添加了一个非常好的搜索功能。

The source/demo is found here: http://harvesthq.github.com/chosen/

源/演示在这里找到:http: //harvesthq.github.com/chosen/