javascript jquery ui自动完成获取所选选项的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15008400/
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:08:28  来源:igfitidea点击:

jquery ui autocomplete get value of selected option

javascriptjqueryjquery-uijquery-ui-autocomplete

提问by Julian

How can i get the value of the selected option in the menu that is created by jquery ui autocomplete into a variable?

如何将 jquery ui autocomplete 创建的菜单中所选选项的值转换为变量?

回答by Hugo Alves

var value = $("#the_input_ID").val();

if you want to be notified when a value is selected you can use something along the lines like this:

如果您想在选择一个值时收到通知,您可以使用类似这样的内容:

var selected_value;
$( "#your_input_id" ).autocomplete({
   select: function(event, ui) {
        selected_value = $(ui).val();
   }
});

回答by Luis Tellez

The input that you use to create the autocomplete stores the value.

用于创建自动完成的输入存储该值。

$("#myField").val();

or you get it if you submit your code with that ID.

或者,如果您使用该 ID 提交代码,您就会得到它。