2012-02-19 67 views

回答

2
$('#combobox').val() might do the trick 

好的,那是不正确的。这样来做:

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

在那里做的console.log($(UI).VAL())或类似的东西

,那么你应该能够做到之一: $(” #combobox').text()或.val()来获取它的内容。

+0

没有..的#combobox是一个HTML选择元素,并自动完成/组合框不“选择”那会是太简单的要素:(之一。 – fbas 2012-02-19 22:40:42

+0

没有,我以前试过'选择'的东西,没有运气。我的#combobox是一个HTML选择,所以.text()刚刚返回整个列表,而不是选择的项目。事实上没有任何人被这个过程选中。我猜我必须阅读手册。 – fbas 2012-02-19 23:53:32

+0

啊。我更深入地考察了他们的代码,并在他们创建的文本输入中添加了一个ID,这样我就可以选择它并获得它的价值。一切都与世界再正确。 – fbas 2012-02-20 00:07:17

1

如果您正在使用“输入”元素,这就是我如何运作的。

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

的JavaScript

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

,将返回选择的值。

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 
} }); 

这可能会让事情变得简单一些。

在简易UI组合框
2

:。
获得的电流值
$( '#组合框')组合框( '的getValue')
获得当前字符串
$( '#组合框')组合框( 'getText')
希望这有助于。

0

第一组ID,然后获取文本框的值和下拉的选项的文本匹配它,如果期权的文本匹配,那么得到它的价值。你可以看到例如here的jsfiddle

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") 
    })