Jquery custom select/combobox

本小妞迷上赌 提交于 2020-01-05 10:32:56

问题


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?


回答1:


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.




回答2:


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:

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




回答3:


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.



来源:https://stackoverflow.com/questions/3990697/jquery-custom-select-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!