jqueryui combobox:我如何获得价值?

时间:2012-02-19 22:23:44

标签: jquery jquery-ui combobox

我从http://jqueryui.com/demos/autocomplete/#combobox借用了代码,但不知道如何获取所选项目的值。

希望得到一个简单的直接答案,而不是在接下来的2个小时内阅读他们的文档。

6 个答案:

答案 0 :(得分:2)

$('#combobox').val() might do the trick
好吧,那不对。这样做:

$( "#combobox" ).autocomplete({
   select: function(event, ui) { ... }
});

在那里做一个console.log($(ui).val())或类似的东西

然后你应该能够做到: $('#combobox')。text()或.val()来获取其内容。

答案 1 :(得分:2)

在Easy UI组合框中


获得当前价值
$( '#组合框')。组合框( '的getValue')
获取当前字符串
$( '#组合框')。组合框( '的getText')
希望这会有所帮助。

答案 2 :(得分:1)

如果你正在使用'input'元素,这就是我使用它的方法。

<input type="text" id="comboBox" />

的JavaScript

$("#comboBox option:selected").val()

这将返回所选的值。

答案 3 :(得分:0)

$(this).combobox({ selected: function (event, obj) { 
  console.log(obj.item.value) // log val 
  window.location.href = obj.item.value; // if you are using a url then give this a go
} }); 

这可能会让事情变得简单易懂。

答案 4 :(得分:0)

您可以使用$('#comboname').combobox('getValue')获取值。

有关详细信息和演示,请参阅此处http://www.jeasyui.com/demo/main/index.php?

答案 5 :(得分:0)

首先设置文本框的ID,然后获取该文本框的值,并将其与下拉选项的文本匹配,如果选项的文本匹配,则获取其值。您可以在jsfiddle中看到示例here

this.input = $("<input>")
     .appendTo(this.wrapper)
     .val(value)
     .attr('placeholder', "Enter Type...")
     .attr("title", "")

     // Set Id of Input Type Text    

     .attr('id', 'Mach')
     .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
     .autocomplete({
     delay: 0,
     minLength: 0,
     source: $.proxy(this, "_source")
     })