多个JQuery UI自动完成框 - 获取所选项的值

时间:2012-12-22 23:14:57

标签: jquery autocomplete jquery-ui-autocomplete

我在页面上有三个jQuery UI“自动填充”输入字段:

<select id="combobox1"><?php putSome1ValuesHere(); ?></select>
<select id="combobox2"><?php putSome2ValuesHere(); ?></select>
<select id="combobox3"><?php putSome3ValuesHere(); ?></select>

将它们全部组合成组合框可以正常工作:

$(function() {
    $( "#combobox1" ).combobox();
    $( "#combobox2" ).combobox();
    $( "#combobox3" ).combobox();
});

我想要做的是根据在组合框中选择的值重定向到另一个页面。如果我将其中一个明确命名为

,则此方法可以正常工作
select: function( event, ui ) {
    ui.item.option.selected = true;
    that._trigger( "selected", event, {
        item: ui.item.option
    });
    window.location.href = $('#combobox1').val() + ".php";
},

我不能做的是根据点击的组合框的值重定向。我无法硬连线,因为可以点击三个盒子中的任何一个。但是,我只是不太了解jQuery来访问已调用'select'函数的框的值。我很感激任何人都可以提供的建议。我想我上面已经包含了足够的信息,但是如果需要的话请告诉我。谢谢!

2 个答案:

答案 0 :(得分:0)

组合框小部件代码select中的

是隐藏的选择标记的jQuery对象

window.location.href = select.val() + ".php";

使用select.val() http://jsfiddle.net/YBFAr/

进行演示

答案 1 :(得分:0)

更改此

select: function( event, ui ) {
  ui.item.option.selected = true;
  that._trigger( "selected", event, {
      item: ui.item.option
 });
 window.location.href = $('#combobox1').val() + ".php";
},

select: function( event, ui ) {
    ui.item.option.selected = true;
    that._trigger( "selected", event, {
    item: ui.item.option
    });
    window.location.href = $(this).val() + ".php";
},

希望这有帮助