Jquery 自定义选择/组合框

发布于 2024-09-28 12:11:38 字数 118 浏览 4 评论 0原文

我正在使用 jQuery;我有一个选择框,其选项是从 json 对象填充的。但由于数据库可能不完整,我想为用户提供输入自定义值的能力。我一直在寻找的大多数组合框解决方案都以某种方式出现故障。在这种情况下有哪些替代解决方案?

I am using jQuery; I have a select box the options of which are populated from a json object. But because the database is potentially incomplete, I would like to offer the user the ablity to enter a custom value. Most combobox solutions, I have been looking at are malfunctioning one way or the other. What are alternative solutions in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

入画浅相思 2024-10-05 12:11:38

您可以使用 jQuery 可编辑组合框插件 来实现此目的。

jQuery 可编辑组合框是一个 jQuery
可以让你转变的功能
任何标签都可编辑
组合框。

这是通过添加一个新的
携带输入值的元素
键盘。这仅适用于
选择元素。任何其他元素
该函数将应用于 will
被忽略。

You can use the jQuery Editable Combobox plugin for that.

jQuery Editable Combobox is a jQuery
function that allows you to transform
any tag into editable
combobox.

This is done by adding a new
element to carry the value entered by
the keyboard. This will only work on
select elements. Any other elements
this function will be applied to will
be ignored.

度的依靠╰つ 2024-10-05 12:11:38

也许是一个自动完成框?用户可以开始输入并显示您的选项,但也可以输入不同的值。例如:

QuickSelect

QuickSelect 插件可以将您的

Maybe an auto-complete box? Where the user can start typing and your options are presented, but a different value can be typed in as well. Like:

QuickSelect

The QuickSelect plug-in can change your <select> box into one of these.
http://github.com/dcparker/jquery_plugins/tree/master/quickselect

七月上 2024-10-05 12:11:38

Professional jQuery based Combobox control? 上的解决方案都侧重于使用输入作为手段过滤并自动完成现有的选择值。

我看到“jQuery 可编辑组合框”的主要问题是它仍然是一个选择列表,而且您可以开始输入新内容这一点并不明显。

如果您正在寻找传统的组合框,即“键入某些内容或从这些预定义值中进行选择”(不,我们不会隐藏您键入时不匹配的值),您可以需要做的是

<select id="combo4" style="width: 200px;"
            onchange="$('input#text4').val($(this).val());">
    <option>option 1</option>
    <option>option 2</option>
    <option>option 3</option>
</select>
<input id="text4"
       style="margin-left: -203px; width: 180px; height: 1.2em; border: 0;" />

查看
http://bit.wisestamp.com/uncategorized/htmljquery-editable-combo -2/

应该很容易将其包装到转换现有选择标签的插件中,尽管我还没有看到这样做。

The solutions on Professional jQuery based Combobox control? all focus on using the input as a means to filtering and autocompleting to an existing select value.

The main problem I see with "jQuery Editable Combobox" is that it remains a select list, and it is not obvious at all that you can just start typing something new.

If you're looking for the traditional combo box, which is simply "Type something or select from these pre-defined values" (no we won't hide the ones that don't match while you're typing), all you may need to do is

<select id="combo4" style="width: 200px;"
            onchange="$('input#text4').val($(this).val());">
    <option>option 1</option>
    <option>option 2</option>
    <option>option 3</option>
</select>
<input id="text4"
       style="margin-left: -203px; width: 180px; height: 1.2em; border: 0;" />

See
http://bit.wisestamp.com/uncategorized/htmljquery-editable-combo-2/

Should be easy to wrap this into a plugin that converts an existing select tag, though I haven't seen that done yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文