[英]How to create a dropdown list with predefined values but there should also be the option to add a new one to the list
[英]How to create dropdown list with “new value” option?
我想創建一個下拉列表,最后一個選項是輸入新值。 我該如何創建呢?
有沒有提供此類功能的jQuery插件?
沒有Html元素可以本地完成您要尋找的功能。
但是,作為解決方法,您可以將更改事件處理程序綁定到下拉列表。 其余的取決於您希望用戶輸入新值的精確程度:
$("#theList").change(function (e) {
//open a thickbox asking for the value, convert the dropdown list to a regular input or whatever...
});
請注意,某些瀏覽器在更改列表框時引發onchange事件,其他瀏覽器僅在更改列表框並失去焦點時才觸發。 因此,如果您希望用戶界面提供一致的行為,則可能還需要監聽mousedown和keydown事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.